I have a df
,
delta1 delta2
0 -1
2 0
-1 0
0 0
I am wondering how to assign values of delta2
to delta1
only if delta1 > 0
and delta2 <= 0
; the result look like,
delta1 delta2
0 -1
0 0
-1 0
0 0
Using numpy.where
:
df['delta1'] = np.where(df.delta1.gt(0) & df.delta2.le(0), df.delta2, df.delta1)
delta1 delta2
0 0 -1
1 0 0
2 -1 0
3 0 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With