Python Pandas: How to use "resample" together with "idxmin"?

179 views Asked by At

I have a dataframe with a pandas datetime index.

    TIMESTAMP          water
2020-06-24 13:50:00   -0.5
2020-06-24 14:00:00   -0.6
2020-06-24 14:10:00   -0.7
2020-06-24 14:30:00   -0.5
2020-06-24 14:40:00   -0.8
...

I want to get the index of the daily minimum value. This is my approach which is not working:

water_daily_min_index = df['water'].resample('D').idxmin()

How can I solve this without creating a loop?

1

There are 1 answers

0
jezrael On BEST ANSWER

Use Grouper like alternative to resample:

water_daily_min_index = df.groupby(pd.Grouper(freq='D'))['water'].idxmin()
print (water_daily_min_index)
TIMESTAMP
2020-06-24   2020-06-24 14:40:00
Freq: D, Name: water, dtype: datetime64[ns]