小编GKS*_*GKS的帖子

Pandas从单列字符串生成列

我有一个csv文件,如下所示:

index,labels
1,created the tower
2,destroyed the tower
3,created the swimming pool
4,destroyed the swimming pool
Run Code Online (Sandbox Code Playgroud)

现在,如果我传递我想要的列的列表代替标签列(不包含标签列中的所有单词)

['created','tower','destroyed','swimming pool']
Run Code Online (Sandbox Code Playgroud)

我想获取数据帧为:

index,created,destroyed,tower,swimming pool
1,1,0,1,0
2,0,1,1,0
3,1,0,0,1
4,0,1,0,1
Run Code Online (Sandbox Code Playgroud)

我调查了get_dummies,但那并没有帮助

python pandas

8
推荐指数
3
解决办法
680
查看次数

标签 统计

pandas ×1

python ×1