if I have the following panda DataFrame
:
pd.DataFrame(columns=['name', 'tags'], data=[
['Rob', ['a', 'c']],
['Erica', ['b', 'c']]
])
table:
Name tags
Rob ['a', 'c']
Erica ['b', 'c']
How would I convert this into:
Name tags_a tags_b tags_c
Rob 1 0 1
Erica 0 1 1
If each row could only have 1 tag I could do this with pd.get_dummies(df, columns=['tags'])
but this doesn't work when tags
is a List
.
str.get_dummies
include
join