3 回答
TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
你可以做
df.update((df.loc[:,'desktop':].astype(str)!='0').astype(int))
df
cust_id desktop laptop accessories
0 123 1 1 0
1 234 1 0 0
2 211 1 0 0
TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
這對(duì)我有用:
df = df.applymap(lambda x: 1 if x != 0 else 0)
輸出:
desktop laptop accessories
cust_id
123 1 1 0
234 1 0 0
211 1 0 0
添加回答
舉報(bào)
