![](/img/trans.png)
[英]Mean of last N rows of pandas dataframe if the previous rows meet a condition
[英]dataframe previous rows mean
我有以下數據框,並希望創建一個新列“ 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
df[‘measurement_mean’] = df.Measurement.expanding().mean()
df['measurement_mean'] = df.Measurement.cumsum()/(df.index+1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.