Skip to content
Advertisement

non fixed rolling window

I am looking to implement a rolling window on a list, but instead of a fixed length of window, I would like to provide a rolling window list:
Something like this:

JavaScript

and the result would be:

JavaScript

6.67 is calculated as average of 3 elements 10, 2, 8.

I implemented a slow solution, and every idea is welcome to make it quicker :):

JavaScript

Advertisement

Answer

Pandas custom window rolling allows you to modify size of window.

Simple explanation: start and end arrays hold values of indexes to make slices of your data.

JavaScript

Arguments passed to get_window_bounds are given by BaseIndexer.

JavaScript
JavaScript

Outputs:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement