首页 > 解决方案 > 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

标签: pythonpandasfunctionloops

解决方案


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()

推荐阅读