Using Titanic dataset, do the following: a. Find total number of passengers with age less than 30 b. Find total fare paid by passengers of first class c. Compare number of survivors of each passenger class

 Using Titanic dataset, do the following:

a. Find total number of passengers with age less than 30

b. Find total fare paid by passengers of first class

c. Compare number of survivors of each passenger class


CODE





import seaborn as sns


# Load the Titanic dataset from seaborn

titanic = sns.load_dataset('titanic')


# Find the total number of passengers with age less than 30

passengers_age_less_than_30 = titanic[titanic['age'] < 30]

total_passengers_age_less_than_30 = len(passengers_age_less_than_30)

print(f"Total number of passengers with age less than 30: {total_passengers_age_less_than_30}")


# Find the total fare paid by passengers of first class

total_fare_first_class = titanic[titanic['class'] == 'First']['fare'].sum()

print(f"Total fare paid by passengers of first class: {total_fare_first_class}")


# Compare the number of survivors of each passenger class

survivors_by_class = titanic.groupby('class')['survived'].sum()

print("Number of survivors by passenger class:")

print(survivors_by_class)


Comments

Popular posts from this blog

Load a Pandas dataframe with a selected dataset. Identify and count the missing values in a dataframe. Clean the data after removing noise as follows: a. Drop duplicate rows. b. Detect the outliers and remove the rows having outliers c. Identify the most correlated positively correlated attributes and negatively correlated attributes

The weights of 8 boys in kilograms: 45, 39, 53, 45, 43, 48, 50, 45. Find the median

Download any dataset and do the following: a. Count number of categorical and numeric features b. Remove one correlated attribute (if any) c. Display five-number summary of each attribute and show it visually