In [6]: # Survival rate for kids > adults?
kid = df['kid/adult'].value_counts()[0] # find the no. of kids on Tit
adult = total - kid # find the no. of adults
print(kid, adult)
sr_age = [Link]('kid/adult')['survived'].mean() # find the survival rate for
sr_age.index = ['kids', 'adults']
print(sr_age)
109 2092
kids 0.522936
adults 0.312620
Name: survived, dtype: float64
Conclusions:
Survival rate for kids (0.5223) > adults (0.3126)
In [5]: # Survival rate of females > males?
female = df['gender'].value_counts()[0] # find the no. of females on
male = total - female # find the no. of males
print(female, male)
sr_gender = [Link]('gender')['survived'].mean() # find the survival rate for
sr_gender.index = ['females', 'males']
print(sr_gender)
470 1731
females 0.731915
males 0.212016
Name: survived, dtype: float64
Conclusions:
Survival rate for kids (0.5223) > adults (0.3126)
Survival rate for females (0.7319) > males (0.2120)
In [7]: # Did Titanic mainly save the girls, not elder women?
sr_gender_age = [Link](index=df['gender'],
columns=df['kid/adult'],
values=df['survived'],
aggfunc='mean'
) # See note
sr_gender_age.index = ['females', 'males']
sr_gender_age.columns = ['kids', 'adults']
print((sr_gender_age))
'''
Note:
- [Link]() is a cross tabulation function in pandas. We use it
to build a cross tabulation between gender and age group.
- As we have 2 gender groups (females & males) and 2 age groups
(kids & adults), the resulting cross tabulation should have 4
groups: female kids, female adults, male kids & male adults.
- For each group, we calculate the mean (i.e., aggfunc = 'mean') of
the survived data (i.e., values = df['survived']), which is the
survival rate of a group.
'''
kids adults
females 0.622222 0.743529
males 0.453125 0.202759
Conclusions:
Survival rate for kids (0.5223) > adults (0.3126)
Survival rate for females (0.7319) > males (0.2120)
Survival rate for female adults (0.7435) > female kids (0.6222)
In other words, Titanic tried to save all the females regardless of their age.
Based on the above findings, the "women and children go first" policy by and large could be
enforced on Titanic.
Possible reasons include the males on Titanic were really noble (i.e., they let the women and
children get into the lifeboats first), or/and Titanic crew had sufficient forces to enforce the
policy.
In [ ]: