0

I have a Dataframe as below:

Datetime             Volume       Price
2020-08-05 09:15:00  1033         504
2020-08-05 09:15:00  1960         516
2020-08-05 09:15:00  1724         520
2020-08-05 09:15:00  1870         540
2020-08-05 09:20:00  1024         576
2020-08-05 09:20:00  1960         548
2020-08-05 09:20:00  1426         526
2020-08-05 09:20:00  1968         518
2020-08-05 09:30:00  1458         511
2020-08-05 09:30:00  1333         534
2020-08-05 09:30:00  1322         555
2020-08-05 09:30:00  1425         567
2020-08-05 09:30:00  1245         598

I want to find the price with highest volume group-by on Datetime column.

Result Dataframe as below:

Datetime             Volume       Price
2020-08-05 09:15:00  1960         516
2020-08-05 09:20:00  1968         518
2020-08-05 09:30:00  1458         511
Pravat
  • 329
  • 2
  • 17
  • 2
    something like `df.loc[df.groupby("Datetime")['Volume'].idxmax()]` should work (however if you may have duplicate maximum values and you want to return all such rows , then use the solution from the duplicate link). – anky Nov 28 '20 at 06:46
  • 1
    You mean this will do.... idx = df.groupby(['Datetime'])['Volume'].transform(max) == df['Volume']..........df[idx] – Pravat Nov 28 '20 at 06:52
  • 1
    Yes: `df[df["Volume"].eq(df.groupby("Datetime")['Volume'].transform("max"))]` – anky Nov 28 '20 at 06:53
  • 1
    Ok. Thanks for the quick help. – Pravat Nov 28 '20 at 06:54

0 Answers0