首页 > 其他分享 >66.移动窗口数据计算

66.移动窗口数据计算

时间:2022-11-27 13:34:16浏览次数:45  
标签:index 01 窗口 pd 2020 66 rolling 15 移动

 

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#移动窗口数据计算
import pandas as pd 
index=pd.date_range('2020-1-1',periods=15,freq='D') 
#创建Series对象
s=pd.Series(data=[3,6,7,4,2,1,3,8,9,10,12,15,13,22,14],index=index) 
#使用rolling函数计算三天的均值
s.rolling(3).mean()    #移动3位数统计平均值
2020-01-01          NaN
2020-01-02          NaN
2020-01-03     5.333333
2020-01-04     5.666667
2020-01-05     4.333333
2020-01-06     2.333333
2020-01-07     2.000000
2020-01-08     4.000000
2020-01-09     6.666667
2020-01-10     9.000000
2020-01-11    10.333333
2020-01-12    12.333333
2020-01-13    13.333333
2020-01-14    16.666667
2020-01-15    16.333333
Freq: D, dtype: float64
#移动窗口数据计算
import pandas as pd 
index=pd.date_range('2020-1-1',periods=15,freq='D') 
#创建Series对象
s=pd.Series(data=[3,6,7,4,2,1,3,8,9,10,12,15,13,22,14],index=index) 
#使用rolling函数计算三天的均值
s.rolling(3,min_periods=1).mean()    #移动3位数统计平均值,最小窗口观测值为1个
2020-01-01     3.000000
2020-01-02     4.500000
2020-01-03     5.333333
2020-01-04     5.666667
2020-01-05     4.333333
2020-01-06     2.333333
2020-01-07     2.000000
2020-01-08     4.000000
2020-01-09     6.666667
2020-01-10     9.000000
2020-01-11    10.333333
2020-01-12    12.333333
2020-01-13    13.333333
2020-01-14    16.666667
2020-01-15    16.333333
Freq: D, dtype: float64

 

标签:index,01,窗口,pd,2020,66,rolling,15,移动
From: https://www.cnblogs.com/988MQ/p/16929525.html

相关文章