Reputation: 303
I want to transform this dataframe:
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]
Into this one:
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]
I tried to use replace:
df.replace([1,1], 1)
But it didn't work.
Upvotes: 0
Views: 59
Reputation: 323316
Using applymap
df.applymap(lambda x : 1 if x==[1,1] else x )
Out[162]:
col1 col2
0 [1, 0] [0, 1]
1 1 1
Upvotes: 2