我要转换此数据框:
col1 col2
0 [1, 0] [0, 1]
1 [1, 1] [1, 1]
2 [0, 1] [1, 0]
3 [0, 1] [1, 1]
4 [1, 1] [0, 1]
5 [1, 0] [1, 0]
进入这个:
col1 col2
0 [1, 0] [0, 1]
1 1 1
2 [0, 1] [1, 0]
3 [0, 1] 1
4 1 [0, 1]
5 [1, 0] [1, 0]
我尝试使用replace:
df.replace([1,1], 1)
但这没用。
答案 0 :(得分:2)
使用applymap
df.applymap(lambda x : 1 if x==[1,1] else x )
Out[162]:
col1 col2
0 [1, 0] [0, 1]
1 1 1