Left-align a pandas rolling object

前端 未结 1 671
一个人的身影
一个人的身影 2021-02-02 11:02

Using pandas 0.18.1, I\'d like to take the rolling average of a one-column dataframe. Since version 0.18.0, this is done with rolling() objects. The default for these rolling ob

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-02 11:50

    I think you can use shift:

    a = df.rolling(window=3).mean().shift(-2)
    print (a)
               A
    0   3.666667
    1   5.666667
    2  11.333333
    3  18.333333
    4        NaN
    5        NaN
    

    0 讨论(0)
提交回复
热议问题