I have the need to do the following: I have a dataset containing the time at which a certain specific vehicle passes at a specific point. I need to insert a column indicating how many times each specific vehicle passes there. Moreover, I need to reset the count each time the delta time between two subsequent passes of the same vehicle is over a certain threshold.
For example:
Vehicle || Time || number times passed
A 00:15 1
B 00:20 1
C 00:25 1
C 00:45 2
A 00:59 2
A 01:56 3
B 22:55 1 (delta time above the threshold, so reset)
A 23:49 1 (delta time above the threshold, so reset)
df['period']=pd.to_datetime(df['date_time'])
dfM['Number'] = df.groupby(['Vehicle']).cumcount().add(1)
I think this just summes up the times without considering the reset above a certain threshold, for which I have absolutely no idea how to do it.