An irregular time series data
is stored in a pandas.DataFrame
. A DatetimeIndex
has been set. I need the time difference between consecutive entries in the index.
I thought it would be as simple as
data.index.diff()
but got
AttributeError: 'DatetimeIndex' object has no attribute 'diff'
I tried
data.index - data.index.shift(1)
but got
ValueError: Cannot shift with no freq
I do not want to infer or enforce a frequency first before doing this operation. There are large gaps in the time series that would be expanded to large runs of nan
. The point is to find these gaps first.
So, what is a clean way to do this seemingly simple operation?