Skip to content

Instantly share code, notes, and snippets.

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