In pandas no, in numpy yes.
You can use numpy.where
or convert boolean Series
created by condition to float
- True
s are 1.0
and False
s are 0.0
:
pd['irr'] = np.where(pd['cs']*0.63 > pd['irr'], 1.0, 0.0)
Or:
pd['irr'] = (pd['cs']*0.63 > pd['irr']).astype(float)
Sample:
pd = pd.DataFrame({'cs':[1,2,5],
'irr':[0,100,0.04]})
print (pd)
cs irr
0 1 0.00
1 2 100.00
2 5 0.04
pd['irr'] = (pd['cs']*0.63 > pd['irr']).astype(float)
print (pd)
cs irr
0 1 1.0
1 2 0.0
2 5 1.0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…