移动平均时间序列分钟熊猫

时间:2019-11-03 06:30:29

标签: python pandas time-series moving-average

在此问题中,我试图在此数据框中获得移动平均值。 每分钟发生的交易数量不同。对应于每笔交易,我试图获取该交易的前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





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

0 个答案:

没有答案