I have the following dataframe:
df = pd.DataFrame({'vehicle':[1,1,1,1,1,2,2,2,1,1,1,2,2,2,2,1,1],
'waypoint':[1,2,3,4,5,1,2,3,1,2,3,1,2,3,4,1,2]})
I need to count the sequences of repeated values in column 'vehicle' in a new column showing how many times a sequence appears. For example, a sequence of vehicle number 1 would be newcolumn number 1, if another sequence of vehicle number 1 appears, newcolumn would be = 2. The desired output for the dataframe above is:
df = pd.DataFrame({'vehicle':[1,1,1,1,1,2,2,2,1,1,1,2,2,2,2,1,1],
'waypoint':[1,2,3,4,5,1,2,3,1,2,3,1,2,3,4,1,2],
'trip':[1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3]})
Thank you