text_html_output_1.png
import pandas as pd

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['Initial'].replace(['Mlle', 'Mme', 'Ms', 'Dr', 'Major', 'Lady', 'Countess', 'Jonkheer', 'Col', 'Rev', 'Capt', 'Sir', 'Don'], ['Miss', 'Miss', 'Miss', 'Mr', 'Mr', 'Mrs', 'Mrs', 'Other', 'Other', 'Other', 'Mr', 'Mr', 'Mr'], inplace=True)
test['Initial'].replace(['Mr', 'Mrs', 'Miss', 'Master', 'Don', 'Rev', 'Dr', 'Mme'], ['Mr', 'Mrs', 'Miss', 'Master', 'Mr', 'Other', 'Mr', 'Mrs'], inplace=True)
print(train['Initial'].unique())
print(test['Initial'].unique())