Skip to content
Advertisement

How to split a pandas time-series by NAN values

I have a pandas TimeSeries which looks like this:

JavaScript

I would like split the pandas TimeSeries everytime there occurs one or more NaN values in a row. The goal is that I have separated events.

JavaScript

I could loop through every row but is there also a smart way of doing that???

Advertisement

Answer

You can use numpy.split and then filter the resulting list. Here is one example assuming that the column with the values is labeled "value":

JavaScript

You will have a list with all the events separated by the NaN values.

Advertisement