text_html_output_2.png text_html_output_1.png
from sklearn.preprocessing import LabelEncoder

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

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

object_list = train.select_dtypes(include=['object']).columns
float_list = train.select_dtypes(include=['float64']).columns
int_list = train.select_dtypes(include=['int64']).columns
one_columns = []
for f in int_list:
    if len(train[f].unique()) == 1:
        one_columns.append(f)
train.drop(columns=one_columns, inplace=True)
test.drop(columns=one_columns, inplace=True)

for f in object_list:
    le = LabelEncoder()
    le.fit(list(train[f].values) + list(test[f].values))
    train[f] = le.transform(list(train[f].values))
    test[f] = le.transform(list(test[f].values))
Y = train['y']
train.drop(columns=['y'], inplace=True, axis=1)
combine = pd.concat([train, test])
for f in object_list:
    temp = pd.get_dummies(combine[f])
    combine = pd.concat([combine, temp], axis=1)
train = combine[:train.shape[0]]
test = combine[train.shape[0]:]

print(train.shape)
print(test.shape)
print(Y.shape)
train_columns = train.columns