application_vnd.jupyter.stderr_output_2.png text_plain_output_1.png
from sklearn.model_selection import train_test_split

from sklearn.preprocessing import OrdinalEncoder

import pandas as pd

train = pd.read_csv('../input/30-days-of-ml/train.csv', index_col=0)
test = pd.read_csv('../input/30-days-of-ml/test.csv', index_col=0)
y = train['target']
features = train.drop(['target'], axis=1)
X = features.copy()
X_test = test.copy()
categorical_cols = [cname for cname in features.columns if features[cname].dtype == 'object']
numerical_cols = [cname for cname in features.columns if features[cname].dtype in ['int64', 'float64']]
my_cols = categorical_cols + numerical_cols

ordinal_encoder = OrdinalEncoder()
print('Before OEing: ', X.shape, X_test.shape)
X[categorical_cols] = ordinal_encoder.fit_transform(features[categorical_cols])
X_test[categorical_cols] = ordinal_encoder.transform(test[categorical_cols])
print('After OEing: ', X.shape, X_test.shape)
X_train, X_valid, y_train, y_valid = train_test_split(X, y, train_size=0.8, test_size=0.2, random_state=17)
print(X_train.shape)
print(X_valid.shape)