text_plain_output_1.png
from sklearn.preprocessing import OneHotEncoder

import pandas as pd

df = pd.read_csv('../input/train.csv')
df_test = pd.read_csv('../input/test.csv')
df['Sex'] = df.Sex.apply(lambda x: 1 if x == 'male' else 0)
df_test['Sex'] = df_test.Sex.apply(lambda x: 1 if x == 'male' else 0)
df['Embarked'] = df.Embarked.apply(lambda x: str(x))
df_test['Embarked'] = df_test.Embarked.apply(lambda x: str(x))
df.Age.fillna(29.699118, inplace=True)
df_test.Age.fillna(29.699118, inplace=True)
df_test.Fare.fillna(35, inplace=True)

df.Embarked.unique()

ohe = OneHotEncoder()
X = ohe.fit_transform(df.Embarked.values.reshape(-1, 1))
X_test = ohe.transform(df_test.Embarked.values.reshape(-1, 1))
ohe.categories_

df = df.drop('Embarked', axis=1)
df_test = df_test.drop('Embarked', axis=1)

df.head()