Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save VincentTatan/0f85fc42f497c9804e01de285bb5f622 to your computer and use it in GitHub Desktop.
Save VincentTatan/0f85fc42f497c9804e01de285bb5f622 to your computer and use it in GitHub Desktop.
def create_dummies_from_categorical_column (df,categorical_features):
df_copy = df.copy()
print('changing {}'.format(list(categorical_features)))
df_result = pd.DataFrame()
for feature in categorical_features:
df_temp = df_copy[feature].str.get_dummies()
df_temp.columns = ['{}_{}'.format(feature,column) for column in df_temp.columns]
df_copy = df_copy.join(df_temp,rsuffix='_dept')
df_copy.drop(categorical_features,axis=1,inplace=True)
return df_copy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment