Finding hour of daily max using Pandas in Python

UPDATE from 2018-09-19:

FutureWarning: pd.TimeGrouper is deprecated and will be removed; Please use pd.Grouper(freq=...)

solution:

In [295]: df.loc[df.groupby(pd.Grouper(freq='D')).idxmax().iloc[:, 0]]
Out[295]:
                                         power
2011-01-01 06:00:00                     1054.6
2011-01-02 06:00:00                     2054.6

Old answer:

try this:

In [376]: df.loc[df.groupby(pd.TimeGrouper('D')).idxmax().iloc[:, 0]]
Out[376]:
                                           power
2011-01-01 06:00:00                       1054.6
2011-01-02 06:00:00                       2054.6

data:

In [377]: df
Out[377]:
                                           power
2011-01-01 00:00:00                       1015.7
2011-01-01 01:00:00                       1015.7
2011-01-01 02:00:00                       1010.3
2011-01-01 03:00:00                       1010.9
2011-01-01 04:00:00                       1021.1
2011-01-01 05:00:00                       1046.0
2011-01-01 06:00:00                       1054.6
2011-01-02 00:00:00                       2015.7
2011-01-02 01:00:00                       2015.7
2011-01-02 02:00:00                       2010.3
2011-01-02 03:00:00                       2010.9
2011-01-02 04:00:00                       2021.1
2011-01-02 05:00:00                       2046.0
2011-01-02 06:00:00                       2054.6

Tags:

Python

Pandas