Skip to content

Instantly share code, notes, and snippets.

@bkaankuguoglu
Last active November 3, 2022 07:57
Show Gist options
  • Select an option

  • Save bkaankuguoglu/622bdfdd6c8e88c67d5fa677389f09ed to your computer and use it in GitHub Desktop.

Select an option

Save bkaankuguoglu/622bdfdd6c8e88c67d5fa677389f09ed to your computer and use it in GitHub Desktop.
def onehot_encode_pd(df, col_name):
dummies = pd.get_dummies(df[col_name], prefix=col_name)
return pd.concat([df, dummies], axis=1).drop(columns=[col_name])
df_features = onehot_encode_pd(df_features, ['month','day','day_of_week','week_of_year'])
@shahmustafa
Copy link

`def onehot_encode_pd(df, cols):
for col in cols:
dummies = pd.get_dummies(df[col], prefix=col)

return pd.concat([df, dummies], axis=1).drop(columns=cols)

df_features = onehot_encode_pd(df_features, ['month','day','day_of_week','week_of_year'])
df_features`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment