Who had a chance to survive on the Titanic?

How to survive on the Titanic?

Long time I was thinking, that this sample is a something as any railway statistic or other theoretical base. When I realise, that it is real list of Titanic passengers any investigations with it became more exciting.
Let's see ones again what we can see in the data about this apocaliptic catastrof.

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.read_csv('c:/1/kaggletrain.csv')
df.head(3)

 

I am particularly interested as a man, what chances of survival men had. This story is quite popular. We all remember the shouts: "Only women and children enter the shawl." Was that really true?

How many mens were there?

len(df[df['Sex']=='male'])

577

Number of all passengers on the list.

len(df['Sex'])

What percent of passengers were men?

print("Men as the percent of passengers:  ",(len(df[df['Sex']=='male'])/len(df['Sex']))*100)

Age has influence on the survival on the Titanic? I think about kids. I see, yes! Statistically younger passengers survived!

df.groupby('Survived').mean()[['Age']]

We remember in that time existed deep differences between social classes. This differences exist also on the board of Titanic. We know from the film, there are three boards, three classes. We remember people from third class how difficult had their situation during the catastrophe.

Let's check their chance for survive on the Titanic.

pd.crosstab(df.Pclass,df.Survived).plot(kind='bar')
plt.title('How many people survived in their classes ')
plt.xlabel('Class')
plt.ylabel('How many people ')
plt.savefig('Tytanik wg klas')

Is it true that mostly men were killed on Titanide, and women in empty boats were mindlessly staring at the sinking ship. How big chance for survival had poor male from third class?

pd.crosstab(df.Sex,df.Survived).plot(kind='bar')
plt.title('Chance for survival according to the sex')
plt.xlabel('Class')
plt.ylabel('How many people ')
plt.savefig('Tytanic-class')

We have just know, most victims were from third class. In another plot we saw that most fatalities was men.
I have no complex analysis contains simultaneously information about sex and class.
Thanks to this we will have a chance check what was a situations of women according to the class.

Is it true pictures with rich women in empty boats against the backdrop of a monstrous ship?

pd.crosstab(index = [df.Survived], columns = [df.Sex, df.Pclass])

kot = pd.crosstab(index = [df.Survived], columns = [df.Sex, df.Pclass])

plt.figure(figsize=(10,2))
sns.heatmap(kot, cmap="BuPu", annot=True, cbar=True)

As we see only three women from the almost hundred died of first class. Same proportion for women was in second class. Half woman survived on the Titanic in class third.

pd.crosstab(index = [df.Survived], columns = [df.Sex, df.Pclass], normalize='columns').applymap('{:.2f}'.format)

Men had a chance to survive on the Titanic?

Men from third class had only 14 Men from the first class had 37 Overall most of men from all classes were victims in this catastrophe.