-1

I have a df as below. There are values for the speed with an indeterminate amount of nan values between the two values. I am trying to replace the nan values with the mean between the two numeric values.

timestamp   ...           Speed km h^-1
0     1434838676097.07006835937500000000  ... 53.02799834399999667767
1     1434838676130.07006835937500000000  ...                     nan
2     1434838676229.07006835937500000000  ...                     nan
3     1434838676328.07006835937500000000  ...                     nan
4     1434838676429.07006835937500000000  ...                     nan
5     1434838676526.07006835937500000000  ...                     nan
6     1434838676625.07006835937500000000  ...                     nan
7     1434838676726.07006835937500000000  ...                     nan
8     1434838676826.07006835937500000000  ...                     nan
9     1434838676924.07006835937500000000  ...                     nan
10    1434838676992.07006835937500000000  ... 51.19200097200000243447

1 Answers1

0

I think you can simply use pandas.Series.interpolate

So here, since you want to fill the nan values with the average of the filled values above and below them it should look like:

df.Speed.interpolate()

This will return a series of all the speed measures and an interpolation for nan values.

madamak
  • 18
  • 3