0
volume price datetime
100 3 2021-09-29 04:00:00-04:00
300 2 2021-09-29 04:30:00-04:00
900 5 2021-09-29 05:30:00-04:00
500 9 2021-09-29 06:00:00-04:00
900 22 2021-09-29 06:30:00-04:00
400 1 2021-09-29 07:00:00-04:00

Return the price with the highest volume. if there are 2 volume that are same, then return the lower price ( it is 5 in this case)

Thanks in advance!!

sj95126
  • 6,520
  • 2
  • 15
  • 34
GinSnipe
  • 63
  • 4
  • 1
    What have you tried? Are you trying to use two conditionals at once, or obtain one result and then reduce it further? – sj95126 Nov 20 '21 at 04:52
  • either works. i only know df['volume].max() to return the max value. the logic should be " if there 2 or even more occurence of the max volume (for example there are 3 rows that has the volume 900), then return the lowest price out of these 3 row) – GinSnipe Nov 20 '21 at 04:58

1 Answers1

1

Here's one way. First, find the row(s) that have the max volume (I left out the datetime column in these examples):

>>> df[df.volume == df.volume.max()]
   volume  price
2     900      5
4     900     22

Then use that result to find the lowest price:

>>> df[df.volume == df.volume.max()].price.min()
5
sj95126
  • 6,520
  • 2
  • 15
  • 34
  • thanks a lot! sorry actually, do you mind advise on one more filter. on top of that if i want to say within certain time frame, find out the max volume, if there are more than 1 max volume, find the mind price. so basically i am thinking adding .between but not sure how to nest it in the function given by you above – GinSnipe Nov 20 '21 at 10:25
  • @GinSnipe: It might be best to open another question for that. There's some details [here](https://stackoverflow.com/questions/29370057/select-dataframe-rows-between-two-dates) that may help. – sj95126 Nov 20 '21 at 14:38