根据对应的值替换值,不满足则保留值



给定以下数据帧,

输入df:

tbody> <<tr>
cost_center Pool_costs
90272
92705
98754
91350

iuc,可以使用isin

filt = df['Cost_centre'].isin([90272, 91350])
df.loc[filt, 'Pool_costs'] = 'B'
print(df)
Cost_centre Pool_costs
0        90272          B
1        92705          A
2        98754          A
3        91350          B

最新更新