python - 移动平均时间序列分钟 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
````````````````````````````````````````````````````````````````````
解决方案
推荐阅读
- wordpress - 每行列出 1 个邮政编码在 woocommerce 中不起作用
- python-3.x - 将调试器断点处的 python 环境链接到 Jupyter 笔记本
- flutter - Dart `File.writeAsString` 或 `File.writeAsBytes` 在 Flutter testWidgets 小部件测试中运行时挂起
- sql - 按顺序获取记录集,直到 n 行
- reactjs - 无法使用上下文提供程序对未安装的组件执行 React 状态更新
- vue.js - 我想在没有构建和没有 CDN 的情况下使用 Vue 3
- python - 如何验证 None 并在 Pandas 中设置值
- python - Android Studio 看不到我的项目(我无法运行它)
- javascript - Google Apps 脚本:如何将 copyTo 函数与本地字符串一起使用
- reactjs - 为什么一个函数会触发而另一个函数不会?[反应]