Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created Feb 4, 2021
Embed
What would you like to do?
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