python - Time Series Calculation using pandas
问题描述
What is the fastest method to write a function for time series calculation that counts consecutive values in the same series ? A For loop or vector
Here is what my data looks like: enter image description here
解决方案
You can use rolling function to calculate the sum of 4 consecutive hours
df.consumption4hr = df.Consumption.groupby(level='Accounts').rolling(window=4).sum()
with that you can just find the list of accounts that has 0 in that column. for example:
df[df.consumption4hr == 0].Accounts.unique()
推荐阅读
- python - 来自 sympy.integrate 和 Heaviside 的奇怪结果
- spring - 是否可以使用 ANT 创建 Spring 5 组件索引?
- python - 如何使用python根据csv中的列名写入标题
- python - 为什么我没有从这段代码中得到任何输出?
- vue.js - 我可以检查我当前的路线是否在给定的路线列表中吗?
- asp.net-core - 如何在 ASP.NET Core Web 部署包中设置 ACL?
- python - 'list' 对象没有属性 'keys'
- c++ - 将变量传递给 curl_easy_setopt C++
- zabbix - zabbix agent 5分钟无法访问
- xml - SwiftUI Decoder.shared 中的 XMLParser