I'm trying to figure out how to forward propagate values in Python Pandas in the following way: Basically, let's say I have a Pandas Series (each element is a time t):
[5, 2, 3, 3, 4, 9, 2, 3, 1, 9, 2, 7, 5, 7, 9, 2, 3, 1]
I'd like each element to be lasting 4 time periods, meaning:
[5, 5, 5, 5, ...]
However, as you can see, my 5s are going to overwrite the 2, 3, 3 etc... In my case, I'd like to keep them all but take the average of all.
In this way, this would be:
[5, 3.5, 3.33, 3.25, ...]
I've tried:
myList = [5, 2, 3, 3, 4, 9, 2, 3, 1, 9, 2, 7, 5, 7, 9, 2, 3, 1]
N=4
np.convolve(myList, np.ones((N,))/N, mode='valid')
But I get:
[3.25,
3.0,
4.75,
4.5,
4.5,
3.75,
3.75,
3.75,
4.75,
5.75,
5.25,
7.0,
5.75,
5.25,
3.75]
Which is not exactly what I was expecting....
Would you know how to do this? Many thanks