I'm looking for a method to to get a weighted average for each row in a way where the calculated weights are halved depending on all the previous values (and that continuing for each row with growing previous values).
So an output like Out[1) should look like Out[2]:
The weights should go from 1/1 to 1/2 to 1/3 to 1/4 to 1/5... etc. depending on previous numbers of observations.
>> Out[1]:
B
0 1
1 2
2 5
3 3
Out[2]:
B
0 1
1 1.66
2 3.455
3 3.080
# Where row 1 is calculated as: (2*1/1 + 1*1/2)/(1/1 + 1/2) = 1.66,
# and row 2 as: (5*1/1 + 2*1/2 + 1*1/3)/(1/1 + 1/2 + 1/3) = 3.455,
# row 3 as: (3*1/1 + 5*1/2 + 2*1/3 + 1*1/4)/(1/1 + 1/2 + 1/3 + 1/4) = 3.080,
# ... and that way keeping forward depending on how much observations I have.
Would it be possible to modify the pandas.ewm() function to get a solution since it has a similar approach? I just can't get my head around on how to make this weighting for each row depending on all previous rows.
Maybe someone is able to convert that into a code working with Python?
