Skip to content
Advertisement

Iterative summation

I’m trying to write a python code that allows me to iteratively sum up the average values of three elements of a list, starting with the third element and its two predecessors. Let me give you an example:

JavaScript

I want to calculate the following:

JavaScript

Since I’m quite new to programming I couldn’t find an effective way of putting this into a function.

Advertisement

Answer

You could use rolling from pandas.

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