使用python pandas计算增量平均值 [英] Calculate an incremental mean using python pandas
本文介绍了使用python pandas计算增量平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想生成一个序列,该序列是时间序列的增量均值.这意味着从第一个日期(索引0)开始,存储在x行中的平均值就是[0:x]值的平均值
I'd like to generate a series that's the incremental mean of a timeseries. Meaning that, starting from the first date (index 0), the mean stored in row x is the average of values [0:x]
data
index value mean formula
0 4
1 5
2 6
3 7 5.5 average(0-3)
4 4 5.2 average(0-4)
5 5 5.166666667 average(0-5)
6 6 5.285714286 average(0-6)
7 7 5.5 average(0-7)
我希望有一种方法可以做到这一点而无需循环利用熊猫.
I'm hoping there's a way to do this without looping to take advantage of pandas.
推荐答案
这是Pandas较新版本的更新(从0.18.0开始)
Here's an update for newer versions of Pandas (starting with 0.18.0)
df['value'].expanding().mean()
或
s.expanding().mean()
这篇关于使用python pandas计算增量平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文