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

import pandas as pd

import seaborn as sns

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

sns.set_style('whitegrid')

def impute_age(cols):
    Age = cols[0]
    Pclass = cols[1]
    if pd.isnull(Age):
        if Pclass == 1:
            return 37
        elif Pclass == 2:
            return 29
        else:
            return 24
    else:
        return Age

train.drop('Cabin', axis=1, inplace=True)

test.drop('Cabin', axis=1, inplace=True)

train = train.fillna(train['Embarked'].value_counts().index[0])
test = test.fillna(test['Fare'].value_counts().index[0])

pd.get_dummies(test['Embarked'], drop_first=True).head()