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]:]

train_columns = train.columns

def df_column_uniquify(df):
    df_columns = df.columns
    new_columns = []
    for item in df_columns:
        counter = 0
        newitem = item
        while newitem in new_columns:
            counter += 1
            newitem = '{}_{}'.format(item, counter)
        new_columns.append(newitem)
    df.columns = new_columns
    return df
train = df_column_uniquify(train)
test = df_column_uniquify(test)
train['y'] = Y

original_col = list(test.drop(columns=object_list).columns)
display(train.head())
display(test.head())