text_html_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

train_df = pd.read_csv('../input/train.csv')

test_df = pd.read_csv('../input/test.csv')

train_df.isnull().sum()

train_df['Initial'] = 0
for i in train_df:
    train_df['Initial'] = train_df.Name.str.extract('([A-Za-z]+)\\.')
pd.crosstab(train_df.Initial, train_df.Sex).T.style.background_gradient(cmap='gist_rainbow')

train_df['Initial'].replace(['Dr', 'Mlle', 'Mme', 'Ms', 'Major', 'Lady', 'Countess', 'Jonkheer', 'Col', 'Rev', 'Capt', 'Sir', 'Don'], ['Other', 'Miss', 'Miss', 'Miss', 'Mr', 'Mrs', 'Mrs', 'Other', 'Other', 'Other', 'Mr', 'Mr', 'Mr'], inplace=True)
pd.crosstab(train_df.Initial, train_df.Sex).T.style.background_gradient(cmap='gist_rainbow')

train_df.groupby('Initial')['Age'].mean()

train_df.loc[train_df.Age.isnull() & (train_df.Initial == 'Mr'), 'Age'] = 32.5
train_df.loc[train_df.Age.isnull() & (train_df.Initial == 'Mrs'), 'Age'] = 36
train_df.loc[train_df.Age.isnull() & (train_df.Initial == 'Master'), 'Age'] = 4.5
train_df.loc[train_df.Age.isnull() & (train_df.Initial == 'Miss'), 'Age'] = 22
train_df.loc[train_df.Age.isnull() & (train_df.Initial == 'Other'), 'Age'] = 44.5

f, ax = plt.subplots()
train_df['Survived'].value_counts().plot.pie(explode=[0, 0.05], autopct='%1.1f%%', shadow=True)
ax.set_title('Survived')
ax.set_ylabel('')
plt.show()