application_vnd.jupyter.stderr_output_1.png
from sklearn.preprocessing import LabelEncoder

import numpy as np

import pandas as pd

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

np.array(list(zip(train.Id, train.columns)))

np.array(list(zip(train.Id, train.columns[train.isnull().any()].tolist())))

np.array(list(zip(train.Id, test.columns[test.isnull().any()].tolist())))

trainNum = train.select_dtypes(include=[np.number])
trainCat = train.select_dtypes(include=[object])
testNum = test.select_dtypes(include=[np.number])
testCat = test.select_dtypes(include=[object])

trainNum.columns[trainNum.isnull().any()].tolist()

np.array(list(zip(train.Id, trainCat.columns[trainCat.isnull().any()].tolist())))

trainCat1 = trainCat.drop(['Alley', 'FireplaceQu', 'PoolQC', 'Fence', 'MiscFeature'], axis=1)

from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()

trainNum['MSSubClass'] = le.fit_transform(trainNum['MSSubClass'].values)
trainNum['OverallQual'] = le.fit_transform(trainNum['OverallQual'].values)
trainNum['OverallCond'] = le.fit_transform(trainNum['OverallCond'].values)
trainNum['YearBuilt'] = le.fit_transform(trainNum['YearBuilt'].values)
trainNum['YearRemodAdd'] = le.fit_transform(trainNum['YearRemodAdd'].values)
trainNum['GarageYrBlt'] = le.fit_transform(trainNum['GarageYrBlt'].values)
trainNum['YrSold'] = le.fit_transform(trainNum['YrSold'].values)

trainCatTransformed = trainCat1.apply(le.fit_transform)

trainFinal = pd.concat([trainNum, trainCatTransformed], axis=1)

trainFinal.head()