I have a time series with gaps (NaN) and I want to find the start and stop index of the longest consecutive sequence where no Nan occurs. I have no clue how to do that.
values = [5468.0,
5946.0,
np.nan,
6019.0,
5797.0,
5879.0,
np.nan,
5706.0,
5986.0,
6228.0,
6285.0,
np.nan,
5667.0,
5886.0,
6380.0,
5988.0,
6290.0,
5899.0,
6429.0,
6177.0]
dates = [Timestamp('2018-10-17 13:30:00'),
Timestamp('2018-10-17 14:00:00'),
Timestamp('2018-10-17 14:30:00'),
Timestamp('2018-10-17 15:00:00'),
Timestamp('2018-10-17 15:30:00'),
Timestamp('2018-10-17 16:00:00'),
Timestamp('2018-10-17 16:30:00'),
Timestamp('2018-10-17 17:00:00'),
Timestamp('2018-10-17 17:30:00'),
Timestamp('2018-10-17 18:00:00'),
Timestamp('2018-10-17 18:30:00'),
Timestamp('2018-10-17 19:00:00'),
Timestamp('2018-10-17 19:30:00'),
Timestamp('2018-10-17 20:00:00'),
Timestamp('2018-10-17 20:30:00'),
Timestamp('2018-10-17 21:00:00'),
Timestamp('2018-10-17 21:30:00'),
Timestamp('2018-10-17 22:00:00'),
Timestamp('2018-10-17 22:30:00'),
Timestamp('2018-10-17 23:00:00')]
I found a lot of solutions here on stack, but they all use days and then count with +-1 but in case of my 30 mins frequency this doesn't work.
I know that I can get True/False with isnull()
and then groupby()
or use dates.diff()[1:]
but I have to less knowledge to find a solution.