Created
May 9, 2020 12:48
-
-
Save VincentTatan/0f85fc42f497c9804e01de285bb5f622 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 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