简体   繁体   English

在熊猫中滚动均值并将均值插入窗口的下一行

[英]Rolling mean in Pandas and insert the mean into the next row of the window

I would like to insert the rolling mean value to the row below and not in the same row as a window. 我想将滚动平均值插入到下面的行中,而不是在与窗口相同的行中。 I could use the shift method to achieve that, however you experts could tip me with much more efficient methods. 我可以使用平移方法来实现这一目标,但是您的专家可以为我提供更有效的方法。 Thank you! 谢谢!

df_ts['mittel'] =df_ts['convertedAccx'].rolling(2,min_periods=2).mean()

具有实际和预期输出的数据框。

It works fine ! 它工作正常!

df1:
   a
0  0
1  0
2  1
3  2

data_dic = {
    "a": [0,0,1,2]
}
df1 = pd.DataFrame(data_dic)

print(df1['a'].rolling(2,min_periods=2).mean())

>>>
0    NaN
1    0.0
2    0.5
3    1.5

Please add a sample of your dataframe if you are still facing the issue. 如果您仍然遇到问题,请添加数据框示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM