0

I have the following DataFrame:

>>> BA_df
                   'BID_price' 'ASK_price'
2017-06-01-09:30   100.00      101.50
2017-06-01-09:35   102.00      101.80
2017-06-01-09:40   101.65      101.82

What I would like to do is make both rows equal to zero if the BID_price is greater than, or equal to, the ASK_price. Otherwise, leave everything as it is. I checked out this question, which uses numpy.select(), but I'm not sure how to implement it in my case.

scrps93
  • 303
  • 4
  • 12

1 Answers1

1

Filter and reindex

df=df.query('BID_price<=ASK_price').reindex(df.index,fill_value=0)
df
Out[724]: 
                  BID_price  ASK_price
2017-06-01-09:30     100.00     101.50
2017-06-01-09:35       0.00       0.00
2017-06-01-09:40     101.65     101.82

Or where (mask)

df=df.where(df.BID_price<=df.ASK_price,0)
df
Out[726]: 
                  BID_price  ASK_price
2017-06-01-09:30     100.00     101.50
2017-06-01-09:35       0.00       0.00
2017-06-01-09:40     101.65     101.82
BENY
  • 317,841
  • 20
  • 164
  • 234