text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

sns.set(style='darkgrid')

train_path = '../input/train.csv'
test_path = '../input/test.csv'
train_df = pd.read_csv(train_path)
test_df = pd.read_csv(test_path)

train_df.shape

missing_data = train_df.isnull().sum()
percent_missing = round(missing_data / train_df.isnull().count() * 100, 2)
missing_df = pd.concat([missing_data.sort_values(ascending=False), percent_missing.sort_values(ascending=False)], axis=1, keys=['Total', 'Percent'])

train_df.columns

temp_df = train_df.copy()
temp_df['Cabin'] = temp_df['Cabin'].fillna('Unknown')
occ_cabins = temp_df['Cabin'].copy()
occ_cabins[occ_cabins != 'Unknown'] = 'Known'
temp_df['Cabin'] = occ_cabins

females = train_df[train_df['Sex'] == 'female']
males = train_df[train_df['Sex'] == 'male']

plt.figure(figsize=(12, 5))

plt.subplot(1, 2, 1)
ax = sns.distplot(males[males['Survived'] == 1]['Age'].dropna(), bins=10, kde=False, label='survived')
ax = sns.distplot(males[males['Survived'] == 0]['Age'].dropna(), bins=10, kde=False, label='not survived')
ax.legend()
ax.set_title('Male')

plt.subplot(1, 2, 2)
ax = sns.distplot(females[females['Survived'] == 1]['Age'].dropna(), kde=False, label='survived')
ax = sns.distplot(females[females['Survived'] == 0]['Age'].dropna(), kde=False, label='not survived')
ax.legend()
ax.set_title('Female')

plt.show()

plt.figure(figsize=(5.5, 5))
sns.pointplot(x='Pclass', y='Survived', data=train_df)