改变位置窗口结果

changing position windowing result

下面是滚动window总和的正常结果:

s = pd.Series(range(5))

s.rolling(window=2).sum()

Out[2]: 
0    NaN
1    1.0
2    3.0
3    5.0
4    7.0
dtype: float64

不过,我希望它是

Out[2]: 
0    1.0
1    3.0
2    5.0
3    7.0
4    NaN
dtype: float64

滚动如何实现这一点window?

提前谢谢你。

让我们一起 shift

window = 2
s.rolling(window = window).sum().shift(-window+1)
Out[270]: 
0    1.0
1    3.0
2    5.0
3    7.0
4    NaN
dtype: float64