且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 pandas 在时间序列数据中查找丢失的分钟数据

更新时间:2023-02-26 15:50:04

isin 将是实现此目的的好方法.但是,最简单的方法是将传感器时间数据展平为单个DatetimeIndex,因此您可以将其与参考DatetimeIndex进行比较.

isin would be good way of doing this. However, the easiest way of doing this would be to flatten your sensor time data into a single DatetimeIndex so you can compare it with a reference DatetimeIndex.

# creating reference DatetimeIndex idx_ref with a minute frequency
end=datetime.now().replace(second=0, microsecond=0)
dt = end - timedelta(days=1)
idx_ref = pd.DatetimeIndex(start=dt, end=end,freq='min')

# idx_dat represents your DatetimeIndex from the sensor
gaps = idx_ref[~idx_ref.isin(idx_dat)]

假设您只对时间间隔感兴趣.

Assuming you are only interested in the time gaps of course.