text_plain_output_1.png
import pandas as pd

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

df.isnull().any()

df = df.dropna()

df.shape

features = ['Pclass', 'Age', 'Sex', 'Cabin', 'Embarked']

x = df[features].copy()
del x['Cabin']

def replace(x):
    Sex = x['Sex']
    if Sex in ['female']:
        return 0
    else:
        return 1
x['Sex'] = x.apply(replace, axis=1)

def replace_1(x):
    Embarked = x['Embarked']
    if Embarked in ['E']:
        return 0
    elif Embarked in ['C']:
        return 1
    else:
        return 2
x['Embarked'] = x.apply(replace_1, axis=1)

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

def replace(x):
    Sex = x['Sex']
    if Sex in ['female']:
        return 0
    else:
        return 1
test['Sex'] = test.apply(replace, axis=1)

def replace_1(x):
    Embarked = x['Embarked']
    if Embarked in ['E']:
        return 0
    elif Embarked in ['C']:
        return 1
    else:
        return 2
test['Embarked'] = test.apply(replace_1, axis=1)

test.dropna()

features = ['Pclass', 'Sex', 'Age', 'Embarked']
test = test[features]
test.isnull().any()