text_plain_output_1.png
import pandas as pd

import seaborn as sns

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

categorical = train.dtypes[train.dtypes == 'object'].index

train.isnull().sum()

train['Initial'] = 0
for i in train:
    train['Initial'] = train.Name.str.extract('([A-Za-z]+)\\.')
test['Initial'] = 0
for i in test:
    test['Initial'] = train.Name.str.extract('([A-Za-z]+)\\.')

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

train.loc[train.Age.isnull() & (train.Initial == 'Mr'), 'Age'] = 33
train.loc[train.Age.isnull() & (train.Initial == 'Mrs'), 'Age'] = 36
train.loc[train.Age.isnull() & (train.Initial == 'Master'), 'Age'] = 5
train.loc[train.Age.isnull() & (train.Initial == 'Miss'), 'Age'] = 22
train.loc[train.Age.isnull() & (train.Initial == 'Other'), 'Age'] = 46
test.loc[test.Age.isnull() & (test.Initial == 'Mr'), 'Age'] = 33
test.loc[test.Age.isnull() & (test.Initial == 'Mrs'), 'Age'] = 36
test.loc[test.Age.isnull() & (test.Initial == 'Master'), 'Age'] = 5
test.loc[test.Age.isnull() & (test.Initial == 'Miss'), 'Age'] = 22
test.loc[test.Age.isnull() & (test.Initial == 'Other'), 'Age'] = 46

train = train.drop(['Ticket', 'Name'], axis=1)
test = test.drop(['Ticket', 'Name'], axis=1)

sns.barplot(x='Age', y='Survived', hue='Sex', data=train)