I need to do a binary transformation of a column containing lists of strings separated by comma.
Can you help me in getting from here:
df = pd.DataFrame({'_id': [1,2,3],
'test': [['one', 'two', 'three'],
['three', 'one'],
['four', 'one']]})
df
_id test
1 [one, two, three]
2 [three, one]
3 [four, one]
to:
df_result = pd.DataFrame({'_id': [1,2,3],
'one': [1,1,1],
'two': [1,0,0],
'three': [1,1,0],
'four': [0,0,1]})
df_result[['_id', 'one', 'two', 'three', 'four']]
_id one two three four
1 1 1 1 0
2 1 0 1 0
3 1 0 0 1
Any help would be very appreciated!