Skip to content

Instantly share code, notes, and snippets.

@erraticgenerator
Last active October 31, 2020 20:54
Show Gist options
  • Save erraticgenerator/29292524b9db891989f7a5a9eebef47a to your computer and use it in GitHub Desktop.
Save erraticgenerator/29292524b9db891989f7a5a9eebef47a to your computer and use it in GitHub Desktop.
mlb = MultiLabelBinarizer()
# one-hot encoding + prefix
df = df.join(pd.DataFrame(mlb.fit_transform(df.pop('variants')),
columns=[x for x in mlb.classes_],
index=df.index))
df = df.join(pd.DataFrame(mlb.fit_transform(df.pop('subsets')),
columns=['subsets_' + x for x in mlb.classes_],
index=df.index))
df = df.join(pd.get_dummies(df['category'], prefix="category")).drop(['category'], axis=1)
df.head(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment