Python如何在應該只是數字的列中替換非數字值目標是在 ["campaignid"] 列中找到所有非數值,并為它們分配一個數值。dataframe:2790 8/31/2019 143679198 2791 8/10/2019 143679198 2792 8/10/2019 brand 2793 8/10/2019 brand 2794 8/10/2019 1436791982795 8/10/2019 site2796 8/10/2019 site我的嘗試cw= cw["campaignid"].replace(cw["campaignid"]({'brand': "283494005"}), inplace=True)#error: NoneType' object is not subscriptable# Tried with for loop as well, but isnt replacing it.count= 0for x in cw.campaignid: if x == "brand": x = "283494005" print(f"brand now is.. {x}") elif x == "site": x = "283494007" print(f"site now is.. {x}") else: count+= 1期望的結果只有數字值2790 8/31/2019 143679198 2791 8/10/2019 143679198 2792 8/10/2019 2834940052793 8/10/2019 2834940052794 8/10/2019 1436791982795 8/10/2019 2834940072796 8/10/2019 283494007
Python如何在應該只是數字的列中替換非數字值
慕碼人2483693
2022-06-07 19:56:00