I am trying to fill in the missing values of a time series like the one below. I am using Python3.
Week Rainfall(cm)
1 1
2 NaN
3 9
4 10
5 11
6 NaN
7 NaN
8 14
I do not want to fill the missing values with the mean. If I were going in by hand and filling in the NaN values, I would probably guess that the rainfall in week 2 would be 5cm and the rainfall in weeks 6 and 7 would be 12cm and 13cm, respectively.
I want to make it so for week 2, the value is the average of week 1 (1cm rainfall) and week 3 (9 cm rainfall). (eg. Week 2 would have 5 cm rainfall).
This gets a little more complicated though...
In weeks 6 and 7, I want to make it so the NaN values get filled with 12 and 13, because if you were to draw a line between week 5 (11 cm rainfall) and week 8 (14 cm rainfall) you would expect the rainfall would be 12cm and 13cm for weeks 6 and 7.
Can anybody think of a way to fill the NaN values in the fashion I described above? I've been googling around for the past few hours on this question and cant seem to find anything.