I have a huge datetime index which is supposed to have 1 minute frequency. I know that there are periods of missing data. I would like to detect all missing data periods and find start and end dates for each of them. So far I figured out how to find missing timestamps:
fullrange = pd.date_range(start = obs.index.min(), end = obs.index.max(), freq = "1T")
missing_dates = obs.index.difference(fullrange)
Now I don't know how to separate missing_dates into periods and find the start and end dates for them.
The obs.index looks like this:
DatetimeIndex(['2020-05-10 09:08:00', '2020-05-10 09:09:00',
'2020-05-10 09:10:00', '2020-05-10 09:11:00',
'2020-05-10 09:12:00', '2020-05-10 09:13:00',
'2020-05-10 09:14:00', '2020-05-10 09:15:00',
'2020-05-10 09:16:00', '2020-05-10 12:24:00', # missing data
...
'2020-07-09 12:35:00', '2020-07-09 12:36:00',
'2020-07-09 12:37:00', '2020-07-09 12:38:00',
'2020-07-09 12:39:00', '2020-07-09 12:40:00',
'2020-07-09 12:41:00', '2020-07-09 12:42:00',
'2020-07-09 12:43:00', '2020-08-09 13:14:00'], # missing data
dtype='datetime64[ns]', name='timestamp', length=86617)
The expected result is a list of missing data periods, each period is a list with [start, end]:
[['2020-05-10 09:16:00', '2020-05-10 12:24:00'], ['2020-07-09 12:43:00', '2020-08-09 13:14:00']]