Sunday, 28 July 2019

Pandas: How do I return a row value once a column reaches a certain value of another column?

Here is a sample of the data - https://i.imgur.com/z8ONFkq.png

Goal:
create a new timestamp column for when running_bid_max greater than or equal to the value in ask_price_target_good. Then create a separate timestamp column for when running_bid_min is less than or equal to ask_price_target_bad.

Note: This will be performed on a large amount of data and needs calculated as fast as possible. I'm hoping I don't have to iterate through all rows via iterrows()

running_bid_min and running_bid_max are calculated using a running.min() and pd.running.max() from a certain time frame in the future (this example is using a 5 minute timeline. So it will be the running min,max 5 minutes from the current time)

Printed Data:
(last 2 rows aren't formatting correctly. Will need to manually shift over if you copy & paste it somewhere else) -

time                        bid_price   ask_price   running_bid_max running_bid_min ask_price_target_good   ask_price_target_bad
2019-07-24 07:59:44.432034  291.06      291.26      291.40          291.09          291.46                  291.06
2019-07-24 07:59:46.393418  291.10      291.33      291.40          291.09  291.53     291.13
2019-07-24 07:59:48.425615  291.10      291.33      291.40          291.09  291.53  291.13
2019-07-24 07:59:50.084206  291.12      291.33      291.40          291.09  291.53  291.13
2019-07-24 07:59:52.326455  291.12      291.33      291.40          291.09  291.53  291.13
2019-07-24 07:59:54.428181  291.12      291.33      291.40          291.09  291.53  291.13
2019-07-24 07:59:58.550378  291.14      291.35      291.40          291.20  291.55  291.15
2019-07-24 08:00:00.837238  291.20      291.35      291.40          291.20  291.55  291.15
2019-07-24 08:00:57.338769  291.40      291.46      291.51          291.40  291.66  291.26
2019-07-24 08:00:59.058198  291.40      291.46      291.96          291.40  291.66  291.26
2019-07-24 08:01:00.802679  291.40      291.46      291.96          291.40  291.66  291.26
2019-07-24 08:01:02.781289  291.40      291.46      291.96          291.45  291.66  291.26
2019-07-24 08:01:04.645144  291.45      291.46      291.96          291.45  291.66  291.26
2019-07-24 08:01:06.491997  291.45      291.46      292.07          291.45  291.66  291.26
2019-07-24 08:01:08.586688  291.45      291.46      292.10          291.45  291.66  291.26



from Pandas: How do I return a row value once a column reaches a certain value of another column?

No comments:

Post a Comment