Pandas monthly rolling operation

前端 未结 2 1192
醉梦人生
醉梦人生 2020-11-30 06:06

I ended up figuring it out while writing out this question so I\'ll just post anyway and answer my own question in case someone else needs a little help.

Problem

2条回答
  •  执笔经年
    2020-11-30 06:28

    Use the "D" offset rather than "M" and specifically use "30D" for 30 days or approximately one month.

    df = df.rolling("30D").sum()
    

    Initially, I intuitively jumped to using "M" as I figured it stands for one month, but now it's clear why that doesn't work.

提交回复
热议问题