Skip to content

Instantly share code, notes, and snippets.

@erraticgenerator
Last active October 31, 2020 20:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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