失败时间戳:
ts_failure = datetime.datetime(2019, 5, 15, 19, 48, 2, 495)
与数据帧中的失败时间戳最接近的时间戳是(2019, 5, 15, 19, 48, 2, 479)
数据帧:
Timestamp
2019-05-15 19:48:02.477
2019-05-15 19:48:02.478
2019-05-15 19:48:02.479
我想在故障时间戳附近找到最近的时间戳,并使用时间增量减去500毫秒,然后打印出新的数据帧,该数据帧的时间戳从(t-500)ms到故障时间的最近时间。你知道吗
我试图用iloc找到最近的索引,但是收到一个明显的错误,说我不能比较timestamp和int。
df.index.get_loc(ts_failure, method='nearest')
TypeError: '<' not supported between instances of 'Timestamp' and 'int'
无法获取abs差异,因为我需要毫秒范围内最接近的时间戳。你知道吗
df.iloc[(df['Timestamp']-ts_failure).abs().argsort()[:]]
感谢您的帮助:)
试试这个:
您应该更改
ts_failure
的表示形式:请注意,时间戳总是以纳秒为单位。所以把时间戳的最后一个值乘以1000。你知道吗
相关问题 更多 >
编程相关推荐