如果状态列包含字符串“新”,我想删除 value1 和 value2 列中的值
数据
id date location status value1 value2 CC 1/1/2022 ny new 12 1 CC 4/1/2022 ny new 1 1 CC 7/1/2022 ny new 1 1 CC 10/1/2022 ny new 1 2 CC 1/1/2023 ny ok 1 2
期望的
id date location status value1 value2 CC 1/1/2022 ny new CC 4/1/2022 ny new CC 7/1/2022 ny new CC 10/1/2022 ny new CC 1/1/2023 ny ok 1 2
我不想要一个 NaN 值,但我希望有一个空白。任何建议表示赞赏
正在做
df.loc[(df.status == 'new') 'value1', 'value2']= np.nan
尝试:
df.loc[(df.status == 'new'), ['value1', 'value2']] = ''