timestamp of failure :
ts_failure = datetime.datetime(2019, 5, 15, 19, 48, 2, 495)
Closest timestamp to the timestamp of failure in the dataframe is (2019, 5, 15, 19, 48, 2, 479)
Dataframe:
Timestamp
2019-05-15 19:48:02.477
2019-05-15 19:48:02.478
2019-05-15 19:48:02.479
I want to find the closest timestamp near the failure timestamp and subtract 500 milliseconds using time delta and print out the new data frame which has timestamps from (t-500)ms to closest time to the time of failure.
I tried to find the nearest index using iloc but received an obvious error saying I cannot compare timestamp and int.
df.index.get_loc(ts_failure, method='nearest')
TypeError: '<' not supported between instances of 'Timestamp' and 'int'
Cannot take the abs difference since I want the closest timestamp in the range of milliseconds.
df.iloc[(df['Timestamp']-ts_failure).abs().argsort()[:]]
Would be grateful for any help :)