Created
April 29, 2019 08:06
-
-
Save codeslord/6fab16aaa0da291461c9bf5d5188b4db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Categorical boolean mask | |
categorical_feature_mask = X.dtypes==object | |
# filter categorical columns using mask and turn it into a list | |
categorical_cols = X.columns[categorical_feature_mask].tolist() | |
# import labelencoder | |
from sklearn.preprocessing import LabelEncoder | |
# instantiate labelencoder object | |
le = LabelEncoder() | |
# apply le on categorical feature columns | |
X[categorical_cols] = X[categorical_cols].apply(lambda col: le.fit_transform(col)) | |
X[categorical_cols].head(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment