我具有以下数据框,并希望创建一个新列“ measurement_mean”,我希望新列中每一行的值都是所有先前“ Measurement”值的均值。
我该怎么做?
Measurement
0 2.0
1 4.0
2 3.0
3 0.0
4 100.0
5 3.0
6 2.0
7 1.0
答案 0 :(得分:3)
df[‘measurement_mean’] = df.Measurement.expanding().mean()
答案 1 :(得分:1)
df['measurement_mean'] = df.Measurement.cumsum()/(df.index+1)