How to use pandas rolling window with custom frequency and data folding

Viewed 97

I want to use a rolling window with pandas series, but I want to apply it every certain period of time. Therefore, not every sample in the series data. Such rolling window would therefore be applied with a certain frequency.

ex. Get a mean of 60s of data, every 30s.

I was able to achieve this using both rolling and resampling

data = values.rolling('60s').mean().resample('30s').mean()

But this is obviously wasting resources, since it first calculates rolling window of very high sampling frequency, and afterwards it downsamples it to a much lower frequency.

Now, there used to be a 'freq' parameter a while back in the rolling window method, but now it is gone and I don't know how to optimize this code, not to do calculations with high sampling frequency, just to downsample it afterwards.

data = values.rolling('60s', freq= '30s').mean()

Isn't there a method to achieve this functionality in the rolling window method, or the resample method? Is there a way to fold the data in the analysis window.

EDIT:

Can this be performed by an indexer somehow, I was not able to find an example?

0 Answers
Related