一个不规则时间序列的数据
存储在pandas.DataFrame
中。已设置DatetimeIndex
。我需要获得索引连续条目之间的时间差。
我认为这很简单
data.index.diff()
但是得到了AttributeError: 'DatetimeIndex' object has no attribute 'diff'
我尝试过
data.index - data.index.shift(1)
但收到
ValueError: Cannot shift with no freq
在执行此操作之前,我不想推断或强制执行首选频率。时间序列中存在大的间隙,这些间隙会扩展成大量的nan
值。关键是先找到这些间隙。
那么,有什么清晰的方法可以执行这个看似简单的操作呢?