希望获得数据帧的连续滚动平均值。
df 看起来像这样
index price
0 4
1 6
2 10
3 12
希望获得持续的价格滚动
目标是让它看起来是所有价格的移动平均值。
index price mean
0 4 4
1 6 5
2 10 6.67
3 12 8
先感谢您!
最佳答案
您可以使用扩展:
df['mean'] = df.price.expanding().mean()
df
index price mean
0 4 4.000000
1 6 5.000000
2 10 6.666667
3 12 8.000000
关于python - 如何在 Pandas 中获得连续滚动平均值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59606531/