In [2]:
import pandas as pd
In [4]:
train = pd.read_csv('data/train.csv')
In [6]:
cnt_male_survived = train[(train['Sex']=='male')&(train['Survived']==1)].shape[0]
cnt_male_dead = train[(train['Sex']=='male')&(train['Survived']==0)].shape[0]
cnt_female_survived = train[(train['Sex']=='female')&(train['Survived']==1)].shape[0]
cnt_female_dead = train[(train['Sex']=='female')&(train['Survived']==0)].shape[0]
print(cnt_male_survived,cnt_male_dead,cnt_female_survived,cnt_female_dead)
109 468 233 81
In [7]:
df = pd.DataFrame({'male':[cnt_male_dead,cnt_male_survived],'female':[cnt_female_dead,cnt_female_survived]})
df
Out[7]:
male female
0 468 81
1 109 233