I have the following dataframe:
Row Bid_price Bid_volume Ask_price Ask_volume
2 2999.0 786.7 -500.0 1403.2
3 3000.0 786.7 -499.9 1407.2
4 2950.0 787.3 -250.1 1407.2
---------------------
56 125.1 2691 36.9 3113.1
57 125 2691.1 37 3133.1
---------------------
117 41.4 3029.7 2999 3835.7
118 40.05 3029.7 3000 3835.7
---------------------
123 39.4 3129.7 NaN NaN
124 36.1 3129.7 NaN NaN
125 36 3134.7 NaN NaN
I need to take the first pair of Bid_price and Bid_volume (2999.0 and 786.7) and compare with ALL pairs of Ask_price and Ask_volume. As long as Bid_volume < Ask_volume AND Bid_price > Ask_price I jump to the next pair of Bid_price and Bid_volume and compare again with ALL pairs of Ask_price and Ask_volume. Bid_Price is decreasing, Bid_Volume is increasing, Ask_Price is increasing, Ask_Volume is increasing. Bid_Price, Bid_Volume have the same length, but Ask_Price and Ask_Volume are shorter.
The output should be the first instance where Bid_volume is > Ask_volume AND Bid_price < Ask_price, so the condition is met. This is the case in line 124 for the pair Bid_Price and Bid_Volume, which matches with line 56 for the pair Ask_Price and Ask_Volume.
The desired output should be:
Row Bid_price Bid_volume
124 36.1 3129.7
Row Ask_price Ask_volume
56 36.9 3113.1
My problem is that I can only evaluate conditions for each row. This returns nothing:
BidAsk = BidAsk[(BidAsk["Bid_volume"] > BidAsk["Ask_volume"]) & (BidAsk["Bid_price"] < BidAsk["Ask_price"])]
BidAsk[["Bid_price","Bid_volume"]]
And this here give a traceback error:
BidAsk = BidAsk.where((BidAsk["Bid_volume"] > BidAsk["Ask_volume"]) & (BidAsk["Bid_Price"] < BidAsk["Ask_Price"]))
BidAsk[["Bid_price", "Bid_volume"]]
Any help much appreciated. Thanks!