My data is like this:
a=pd.DataFrame({'id':[0,1,2,3,4,5,6,7,8,9],
'value':[np.nan,np.nan,0,np.nan,np.nan,1,2,np.nan,3,np.nan]})
I want to fill the missing values based on the previous known values. If there is no previous values, then fill -1. So, the result should look like:
id value
0 -1
1 -1
2 0
3 0
4 0
5 1
6 2
7 2
8 3
9 3
My current way is to find all the known values and their positions, then scan the whole table. But there should be a better way which I am not aware of. What can I try here?