我需要对包含由comma
分隔的字符串列表的列进行二进制转换。python - 包含多个词的列的二进制编码
你能帮助我在及彼:
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]
到:
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
任何帮助将是非常赞赏!
很酷..非常感谢! – Codutie