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!!

2
  • 1
    What have you tried? Are you trying to use two conditionals at once, or obtain one result and then reduce it further? Commented Nov 20, 2021 at 4: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) Commented Nov 20, 2021 at 4:58

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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: It might be best to open another question for that. There's some details here that may help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.