首页 > 解决方案 > 移动平均时间序列分钟 Pandas

问题描述

在这个问题中,我试图在这个数据框中获得移动平均线。每分钟发生不同数量的交易。对应于每笔交易,我试图获得该交易前 2 分钟内发生的所有流量值的 MA(假设在时间 t)

m = timedelta(minutes = 1)
for dt in df.DateTime: # for dt time row in datetime column
    obs(dt-m)= Flow(df.iloc[dt-m,1]).mean #Calculate mean of flow values happening at one minute before dt time
    obs(dt-m*2)= GPL_Density(df.iloc[dt-m*2,1]).mean #Calculate mean of flow values happening at two minutes before dt time
    df.loc[df.GPL_Density]= (obs(dt-m),obs(dt-m*2)).mean
DateTime    Flow
1/11/2017 6:01  600
1/11/2017 6:01  600
1/11/2017 6:02  600
1/11/2017 6:02  600
1/11/2017 6:02  600
1/11/2017 6:02  600
1/11/2017 6:03  780
1/11/2017 6:03  780
1/11/2017 6:03  780
1/11/2017 6:04  480





````````````````````````````````````````````````````````````````````

标签: pythonpandastime-seriesmoving-average

解决方案


推荐阅读