-
-
Save amankharwal/eabd2a6902962f53b8f4124f0ab06874 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def get_categorical_indicies(X): | |
cats = [] | |
for col in X.columns: | |
if is_numeric_dtype(X[col]): | |
pass | |
else: | |
cats.append(col) | |
cat_indicies = [] | |
for col in cats: | |
cat_indicies.append(X.columns.get_loc(col)) | |
return cat_indicies | |
categorical_indicies = get_categorical_indicies(X) | |
def convert_cats(X): | |
cats = [] | |
for col in X.columns: | |
if is_numeric_dtype(X[col]): | |
pass | |
else: | |
cats.append(col) | |
cat_indicies = [] | |
for col in cats: | |
X[col] = X[col].astype('category') | |
convert_cats(X) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment