text_html_output_1.png
import pandas as pd

df = pd.read_csv('../input/train.csv', encoding='ISO-8859-1', low_memory=False)

df.columns.values

df['Age_band'] = 0
df.loc[df['Age'] <= 16, 'Age_band'] = 0
df.loc[(df['Age'] > 16) & (df['Age'] <= 32), 'Age_band'] = 1
df.loc[(df['Age'] > 32) & (df['Age'] <= 48), 'Age_band'] = 2
df.loc[(df['Age'] > 48) & (df['Age'] <= 64), 'Age_band'] = 3
df.loc[df['Age'] > 64, 'Age_band'] = 4

df.Age.isnull().sum()

pd.crosstab(df.Pclass, df.Survived, margins=True).style.background_gradient(cmap='summer_r')

df['Title'] = None
for index, row in enumerate(df['Name']):
    title = row.split(', ')[1].split('. ')[0]
    if title in ['Capt', 'Col', 'Don', 'Jonkheer', 'Major', 'Mr', 'Rev', 'Sir']:
        df.loc[index, 'Title'] = 'Mr'
    elif title in ['Ms', 'Mme', 'Mrs', 'the Countess', 'Lady']:
        df.loc[index, 'Title'] = 'Mrs'
    elif title in ['Master']:
        df.loc[index, 'Title'] = 'Master'
    elif title in ['Miss', 'Mlle']:
        df.loc[index, 'Title'] = 'Ms'
    else:
        df.loc[index, 'Title'] = 'Other'

pd.crosstab(df.Title, df.Survived, margins=True).style.background_gradient(cmap='summer_r')

df