I have a dataframe containing a timestamp column. My objective is to find the first timestamp for every row that is greater than the timestamp of the row by a given offset (say 0.01 sec). I tried using the answer given here, in a modified way like:
def getTime(col, base, offset=0.01):
later = filter(lambda d: d > base+dt.timedelta(seconds=offset), col)
return min(later)
testTbt['testTime']=testTbt['exchTstamp'].apply(lambda time: getTime(testTbt[testTbt['exchTstamp']>time]['exchTstamp'].iloc[0:100].tolist(), time, 0.01))
But got the error: ValueError: min() arg is an empty sequence
.
The timestamps are of microsecond level, contain duplicate values and are in increasing order.
Here is the initial rows of the data frame:
exchTstamp seqNum prev10mSecAvg prev1SecAvg imbRegime
0 2019-08-14 09:15:00.022991 199 0.000000 0.000000 0
1 2019-08-14 09:15:00.022995 200 -0.166667 -0.166667 3
2 2019-08-14 09:15:00.022999 201 -0.277778 -0.277778 2
3 2019-08-14 09:15:00.023003 202 -0.333333 -0.333333 2
4 2019-08-14 09:15:00.023007 203 -0.386667 -0.386667 2
A csv of the data can be downloaded here.
Expected output is an added column in the dataframe containing the first timestamp from subsequent timestamps which is minimum 0.01sec greater than current row's timestamp. Eg:- for given dataset, the new column for the first row (having time 09:15:00.022995
) should have value 09:15:00.033136
. Same for every subsequent rows.
A little guidance would be of much help.