In [1]:
import pandas as pd
train = pd.read_csv('data/train.csv')

과제1

In [4]:
survived_male = train.loc[(train['Sex'] == 'male') & (train['Survived'] == 1), 'PassengerId'].count()
survived_female = train.loc[(train['Sex'] == 'female') & (train['Survived'] == 1), 'PassengerId'].count()
dead_male = train.loc[(train['Sex'] == 'male') & (train['Survived'] == 0), 'PassengerId'].count()
dead_female = train.loc[(train['Sex'] == 'female') & (train['Survived'] == 0), 'PassengerId'].count()

df = pd.DataFrame({ 'male': [dead_male, survived_male], 'female': [dead_female, survived_female] }, index=['Dead', 'Survived'])

df
Out[4]:
male female
Dead 468 81
Survived 109 233

과제2

In [5]:
%matplotlib inline

import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
In [6]:
sns.catplot(data=train, x='Survived', hue='Sex', kind='count')
Out[6]:
<seaborn.axisgrid.FacetGrid at 0x1d5fe87f0c8>
In [7]:
sns.catplot(data=train, x='Survived', hue='Pclass', kind='count')
Out[7]:
<seaborn.axisgrid.FacetGrid at 0x1d5fcde9e48>
In [ ]: