Althogh in case of multiple nan
's in a row it doesn't produce the exact output you specified, other users reaching this page may actually prefer the effect of the method interpolate()
:
df = df.interpolate()
print(df)
val
0 1.0
1 2.5
2 4.0
3 5.0
4 7.5
5 10.0
6 1.0
7 2.0
8 5.0
9 6.3
10 7.7
11 9.0