I have a following dataframe:
A label
0 1.0 a
1 2.0 a
2 3.0 a
3 NaN a
4 NaN a
5 NaN a
6 9.0 a
7 8.0 a
8 7.0 a
9 NaN a
10 NaN a
11 21.0 a
12 32.0 a
13 12.0 a
I want to fill nan values in the column A as follow:
Fill null values at index 3,4 and 5: by taking average of values at index 2 and 6 i.e. (3+9)/2.
Fill null values at index 9 and 10: by taking average of values at index 8 and 11 i.e. (7+21)/2.
And similarly for all other null values in the dataframe, if occurs. I have spent a lot of time thinking about the precise solution, but couldn't find one. How can I do that?