text_html_output_1.png
from sklearn.preprocessing import OrdinalEncoder

import pandas as pd

train_data_file_path = '../input/30-days-of-ml/train.csv'
test_data_file_path = '../input/30-days-of-ml/test.csv'

df_train = pd.read_csv(train_data_file_path, index_col=0)
df_test = pd.read_csv(test_data_file_path, index_col=0)

y = df_train['target']
features = df_train.drop(['target'], axis=1)

object_cols = [col for col in features.columns if 'cat' in col]
X = features.copy()
X_test = df_test.copy()
ordinal_encoder = OrdinalEncoder()
X[object_cols] = ordinal_encoder.fit_transform(features[object_cols])
X_test[object_cols] = ordinal_encoder.transform(df_test[object_cols])
X.head()