There is a DataFrameGroupby with the following data:

last vol datetime 2013-07-23 10:00:00 112450 49 2013-07-23 10:00:00 112440 67 2013-07-23 10:00:00 112430 93 2013-07-23 10:00:00 112420 52 2013-07-23 10:00:00 112410 63 last vol datetime 2013-07-23 10:01:00 112690 17 2013-07-23 10:01:00 112680 59 2013-07-23 10:01:00 112670 226 2013-07-23 10:01:00 112660 184 2013-07-23 10:01:00 112650 289 

Grouped by index level:

 blocks_group = datetime_group.groupby(level=0) 

How to get the whole row from each group with the maximum value, and not just the values ​​of the vol column?

    1 answer 1

    Source DataFrame:

     In [47]: df Out[47]: last vol datetime 2018-08-31 10:00:00 112450 49 2018-08-31 10:00:00 112440 67 2018-08-31 10:00:00 112430 93 2018-08-31 10:00:00 112420 52 2018-08-31 10:00:00 112410 63 2018-08-31 10:01:00 112690 17 2018-08-31 10:01:00 112680 59 2018-08-31 10:01:00 112670 226 2018-08-31 10:01:00 112660 184 2018-08-31 10:01:00 112650 289 

    Decision:

     In [48]: df.groupby(level=0, as_index=False).apply(lambda x: x.nlargest(1, 'vol')) Out[48]: last vol datetime 0 2018-08-31 10:00:00 112430 93 1 2018-08-31 10:01:00 112650 289 

    Another less idiomatic option:

     In [51]: df.sort_values('vol').groupby(level=0).tail(1) Out[51]: last vol datetime 2018-08-31 10:00:00 112430 93 2018-08-31 10:01:00 112650 289