I am desperatly searching for a solution with pandas. Maybe you could help me.
I am looking for a rolling mean with consideration of the previous mean.
df looks like this:
| index | count |
|---|---|
| 0 | 4 |
| 1 | 6 |
| 2 | 10 |
| 3 | 12 |
now, using the rolling(window=2).mean() function I would get something like this:
| index | count | r_mean |
|---|---|---|
| 0 | 4 | NaN |
| 1 | 6 | 5 |
| 2 | 10 | 8 |
| 3 | 12 | 11 |
I would like to consider the mean from the first calculation, like this:
| index | count | r_mean |
|---|---|---|
| 0 | 4 | NaN |
| 1 | 6 | 5 |
| 2 | 10 | 7.5 |
| 3 | 12 | 9.5 |
where,
row1: (4+6)/2=5
row2: (5+10)/2=7.5
row3: (7.5+12)/2=9.75
thank you in advance!