I would like tu sum the last X = 12 (in this case) values of a distribution given the following conditions:
- if there are less than 12 values it will do the cumulative sum of the values that exist.
- If there are more than 12 values it will sum the last 12.
I have been using the Numpy cumsum function to do cumulative sums, but this sums from the beginning to the end, y_position = np.cumsum(y_EBITDA)
and I just want a cumulative of "X" number of values I determined.
Below I have an example of the input I have (EBITDA) and the output I need (Sum EBITDA 12M)
EBITDA Sum EBITDA 12M
1 1
1 2
1 3
1 4
1 5
2 7
4 11
1 12
1 13
1 14
4 18
1 19
1 19
1 19
3 21
1 21
1 21
1 20
1 17
1 17
1 17
1 17
1 14