Replace NaN with nearest value in a series of non-numeric object?

Viewed 831

I'm using Pandas and Numpy and I'm trying to replace all NaN values in a Series like this one:

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]

with the nearest objcet (a Numpy array in this case). The result is:

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]

Does someone know an efficient method to do it? Many thanks.

1 Answers
Related