Skip to content

Instantly share code, notes, and snippets.

@bkaankuguoglu
Created March 29, 2021 23:25
Show Gist options
  • Select an option

  • Save bkaankuguoglu/8d390eaf87c1459cb016be300bf2e09b to your computer and use it in GitHub Desktop.

Select an option

Save bkaankuguoglu/8d390eaf87c1459cb016be300bf2e09b to your computer and use it in GitHub Desktop.
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
def onehot_encode(df, onehot_columns):
ct = ColumnTransformer(
[('onehot', OneHotEncoder(drop='first'), onehot_columns)],
remainder='passthrough'
)
return ct.fit_transform(df)
onehot_columns = ['hour']
onehot_encoded = onehot_encode(df_features, onehot_columns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment