Grouping DataFrame by start of decade using pandas Grouper

后端 未结 4 654
死守一世寂寞
死守一世寂寞 2021-01-12 15:05

I have a dataframe of daily observations from 01-01-1973 to 12-31-2014.

Have been using Pandas Grouper and everything has worked fine for each frequency until now:

4条回答
  •  情书的邮戳
    2021-01-12 15:24

    You can do a little arithmetic on the year to floor it to the nearest decade:

    df.groupby(df.index.year // 10 * 10).mean()
    

提交回复
热议问题