I have a column in a df that’s made up of different film genres. I’d like to split them into separate columns:
[Drama, Romance, Thriller]
[Adventure, Fantasy, Action, Science Fiction]
I’d like the output to look like this:
Drama Romance Thriller Adventure etc.
Is there a way that I can do this?
Thanks
I’ve tried changing it into a set, didn’t work, the internet is full of for loop options that haven’t worked either.
This:
from sklearn.preprocessing import MultiLabelBinarizer
mlb = MultiLabelBinarizer()
df = df.join(pd.DataFrame(mlb.fit_transform(test['genres']),
columns=mlb.classes_,
index=df.index))
Returned the following error:
ValueError: Shape of passed values is (10843, 20), indices imply (10866, 20)
Jules_H is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.