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
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
Post a Comment