在一系列非数字对象中用最接近的值替换NaN?

时间:2017-07-18 21:49:13

标签: python-2.7 pandas numpy time-series nan

我正在使用Pandas和Numpy而我正试图替换系列中的所有NaN值,如下所示:

date                    a
2017-04-24 01:00:00  [1,0,0]
2017-04-24 01:20:00  [1,0,0]
2017-04-24 01:40:00  NaN
2017-04-24 02:00:00  NaN
2017-04-24 02:20:00  [0,1,0]
2017-04-24 02:40:00  [1,0,0]
2017-04-24 03:00:00  NaN
2017-04-24 03:20:00  [0,0,1]
2017-04-24 03:40:00  NaN
2017-04-24 04:00:00  [1,0,0]

与最近的objcet(在这种情况下为Numpy数组)。结果是:

date                    a
2017-04-24 01:00:00  [1,0,0]
2017-04-24 01:20:00  [1,0,0]
2017-04-24 01:40:00  [1,0,0]
2017-04-24 02:00:00  [0,1,0]
2017-04-24 02:20:00  [0,1,0]
2017-04-24 02:40:00  [1,0,0]
2017-04-24 03:00:00  [1,0,0]
2017-04-24 03:20:00  [0,0,1]
2017-04-24 03:40:00  [0,0,1]
2017-04-24 04:00:00  [1,0,0]

有人知道这样做的有效方法吗?非常感谢。

1 个答案:

答案 0 :(得分:7)

删除空值,然后填写reindex

celery.task.control