用Python中两个值之间的平均值替换列中的nan

时间:2019-12-14 13:37:52

标签: python pandas

我有一个df,如下所示。存在速度值,两个值之间的nan值不确定。我正在尝试用两个数值之间的平均值替换nan值。

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 个答案:

答案 0 :(得分:0)

我认为您可以简单地使用pandas.Series.interpolate

因此,在这里,由于要用大于或小于它们的填充值的平均值来填充nan值,因此应如下所示:

df.Speed.interpolate()

这将返回一系列所有速度测量值以及nan值的插值。