我有以下Pandas Dataframe :
df = pd.DataFrame({'pred': [1, 2, 3, 4],
'a': [0.4, 0.6, 0.35, 0.5],
'b': [0.2, 0.4, 0.32, 0.1],
'c': [0.1, 0, 0.2, 0.2],
'd': [0.3, 0, 0.1, 0.2]})
我想根据a、b、c、d列更改"pred"列的值,如下所示:
- 如果**a的a列值大于b、c、d列值
以及
- 如果**b、c或d列之一的值大于0.25
然后将"pred"中的值更改为0。因此结果应为:
pred a b c d
0 1 0.4 0.2 0.1 0.1
1 0 0.6 0.4 0.0 0.0
2 0 0.35 0.32 0.2 0.3
3 4 0.5 0.1 0.2 0.2
我该怎么做呢?
2条答案
按热度按时间hmae6n7t1#
创建布尔条件/掩码,然后使用
loc
将值设置为0
,其中条件为True
2jcobegt2#
输出: