In [10]:
import pandas as pd
train=pd.read_csv('data/train.csv')
train.head()
Out[10]:
PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked
0 1 0 3 Braund, Mr. Owen Harris male 22.0 1 0 A/5 21171 7.2500 NaN S
1 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 0 PC 17599 71.2833 C85 C
2 3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.9250 NaN S
3 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 0 113803 53.1000 C123 S
4 5 0 3 Allen, Mr. William Henry male 35.0 0 0 373450 8.0500 NaN S
In [14]:
cnt = train.loc[(train['Sex'] == 'male') & (train['Pclass'] == 1), 'PassengerId'].count()
print(cnt)
122
In [23]:
cnt = train.loc[(train['Sex'] == 'male') & (train['Pclass'] == 1) & (train['Fare'] >= 50), 'PassengerId'].count()
print(cnt)
58
In [33]:
dead_F =train.loc[(train['Sex'] == 'female') & (train['Survived'] == 0), 'PassengerId'].count()
print(dead_F)
81
In [35]:
dead_M =train.loc[(train['Sex'] == 'male') & (train['Survived'] == 0), 'PassengerId'].count()
print(dead_M)
468
In [38]:
live_F =train.loc[(train['Sex'] == 'female') & (train['Survived'] == 1), 'PassengerId'].count()
print(live_F)
233
In [40]:
live_M =train.loc[(train['Sex'] == 'male') & (train['Survived'] == 1), 'PassengerId'].count()
print(live_M)
109
In [46]:
df=pd.DataFrame({ 'male': [dead_M, live_M], 'female': [dead_F, live_F] })
df
Out[46]:
male female
0 468 81
1 109 233
In [51]:
df = pd.DataFrame({ 'male': [dead_M, live_M], 'female': [dead_F, live_F] }), index=['Dead', 'live'])
df
  File "<ipython-input-51-55f8ccca602d>", line 1
    df = pd.DataFrame({ 'male': [dead_M, live_M], 'female': [dead_F, live_F] }), index=['Dead', 'live'])
                                                                                                       ^
SyntaxError: invalid syntax
In [53]:
%matplotlib inline

import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
In [55]:
sns.catplot(data=train, x='Survived', hue='Sex', kind='count')
Out[55]:
<seaborn.axisgrid.FacetGrid at 0x20713210108>
In [57]:
sns.catplot(data=train, x='Pclass', hue='Survived', kind='count')
Out[57]:
<seaborn.axisgrid.FacetGrid at 0x20713341b88>
In [59]:
sns.catplot(data=train, x='Embarked', hue='Survived', kind='count')
Out[59]:
<seaborn.axisgrid.FacetGrid at 0x207133faa08>
In [60]:
sns.catplot(data=train, x='Age', hue='Survived', kind='count')
Out[60]:
<seaborn.axisgrid.FacetGrid at 0x207134b49c8>