I have dataframe of genres
df = pd.DataFrame({'genres': [['Drama'], ['Music', 'Drama', 'Romance'],
['Action', 'Adventure', 'Comedy'],
['Thriller', 'Romance', 'Drama'],
['Adventure', 'Family']]
})
print(df)
genres = ['Action', 'Adventure', 'Comedy', 'Drama', 'Family', 'Music', 'Romance', 'Thriller'] # list of all genres
data:
genres
0 [Drama]
1 [Music, Drama, Romance]
2 [Action, Adventure, Comedy]
3 [Thriller, Romance, Drama]
4 [Adventure, Family]
i want to have output like:
genres Action Adventure Comedy Drama Family \
0 [Drama] 0 0 0 1 0
1 [Music, Drama, Romance] 0 0 0 1 0
2 [Action, Adventure, Comedy] 1 1 1 0 0
3 [Thriller, Romance, Drama] 0 0 0 1 0
4 [Adventure, Family] 0 1 0 0 1
Music Romance Thriller
0 0 0 0
1 1 1 0
2 0 0 0
3 0 1 1
4 0 0 0