【发布时间】:2020-07-15 07:27:53
【问题描述】:
我有如下datafarme。
ID COUNTRY GENDER AGE V1 V2 V3 V4 V5
1 1 1 53 APPLE apple bosck APPLE123 xApple111t
2 2 2 51 BEKO beko SIMSUNG SamsungO123 ttBeko111t
3 3 1 24 SAMSUNG bosch SEMSUNG BOSC1123 uuSAMSUNG111t
如果列表中有相同的值或包含特定值,我想替换为 np.nan。 我在下面尝试但出现错误。
remove_list = ['APPLE', 'BEKO']
remove_contain_list = ['SUNG', 'bosc']
df.iloc[:,4:].str.replace(remove_list, np.nan, case=False) # exact match & case sensitive
df.iloc[:,4:].str.contains(remove_contain_list, np.nan, case=False) # contain & case sensitive
我该如何解决这些问题?
【问题讨论】:
-
你能正确格式化你的代码吗?数据应至少缩进四个空格
标签: python string pandas replace contains