Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created February 4, 2021 09:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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