text_plain_output_1.png
import pandas as pd

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

train.shape

train.nunique()

test.shape

train.nunique()

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

def train_age(cols):
    Age = cols[0]
    Pclass = cols[1]
    if pd.isnull(Age):
        if Pclass == 1:
            return 37
        if Pclass == 2:
            return 29
        else:
            return 24
    else:
        return Age
def test_age(cols):
    Age = cols[0]
    Pclass = cols[1]
    if pd.isnull(Age):
        if Pclass == 1:
            return 42
        if Pclass == 2:
            return 26.5
        else:
            return 24
    else:
        return Age

train = train[train['Fare'] < 300].reset_index(drop=True)

sex_train = pd.get_dummies(train['Sex'], drop_first=True)
sex_test = pd.get_dummies(test['Sex'], drop_first=True)
embark_train = pd.get_dummies(train['Embarked'], drop_first=True)
embark_test = pd.get_dummies(test['Embarked'], drop_first=True)

train = pd.concat([train, sex_train, embark_train], axis=1)
test = pd.concat([test, sex_test, embark_test], axis=1)

train.head(2)