Reputation: 95
So is there any quick and easy way to iterate through data frame? My index is a date, and my other column is the difference between two time series. What I want to do is to get min()
, max()
and avr()
values for each unique day.
difference
date
2017-07-08 505017
2018-01-12 232143
2018-02-04 127792
2018-03-06 98835
2018-03-09 146702
2018-03-12 64094
2018-03-14 84029
2018-03-14 87257
2018-03-20 172057
Upvotes: 1
Views: 701
Reputation: 51165
It would have been helpful if you had provided a DataFrame with more than one duplicate, but you can use pd.Grouper
and agg
:
df.groupby(pd.Grouper(freq='1D')).agg({'difference': ['min', 'max', 'mean']}).dropna()
difference
min max mean
date
2017-07-08 505017.0 505017.0 505017.0
2018-01-12 232143.0 232143.0 232143.0
2018-02-04 127792.0 127792.0 127792.0
2018-03-06 98835.0 98835.0 98835.0
2018-03-09 146702.0 146702.0 146702.0
2018-03-12 64094.0 64094.0 64094.0
2018-03-14 84029.0 87257.0 85643.0 # This was the only duplicate
2018-03-20 172057.0 172057.0 172057.0
Upvotes: 1