In [4]:
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

import seaborn as sns
sns.set()

train = pd.read_csv('data/train.csv')
train.head()
Out[4]:
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 [8]:
a = train.loc[(train['Sex']=='male')& (train['Pclass']==1), 'PassengerId'].count()
print(a)
122
In [16]:
b = train.loc[(train['Sex']=='male')& (train['Pclass']==1)&(train['Fare']>=50),'PassengerId'].count()
print(b)
58
In [17]:
survived_male = train.loc[(train['Sex'] == 'male') & (train['Survived'] == 1), 'PassengerId'].count()
In [19]:
dead_male = train.loc[(train['Sex']=='male') & (train['Survived']==0), 'PassengerId'].count()
In [20]:
survived_female = train.loc[(train['Sex'] == 'female') & (train['Survived'] == 1), 'PassengerId'].count()
In [21]:
dead_female = train.loc[(train['Sex'] == 'female') & (train['Survived'] == 0), 'PassengerId'].count()
In [26]:
df = pd.DataFrame({'male':[dead_male, survived_male], 'female':[dead_female,survived_female]} )
df
Out[26]:
male female
0 468 81
1 109 233
In [27]:
 
In [29]:
plt.bar([survived_male,dead_male],[survived_female,dead_female])
Out[29]:
<BarContainer object of 2 artists>
In [ ]: