title: Mark "trips" in time series using: groupby idcolumn and cumsum of timedelta
body: <p>I have a dataframe that looks roughly like this:</p>
  
  <pre><code>    carid                 timestamp             speed       brake,....
  0   00056f66da29e6b615aa  2017-07-18 03:46:15   NaN 0.0
  1   00056f66da29e6b615aa  2017-07-18 03:46:20   0.842667    0.5
  2   00056f66da29e6b615aa  2017-07-18 03:46:25   6.704000    0.5
  3   00056f66da29e6b615aa  2017-07-18 03:46:30   11.746000   NaN
  4   00056f66da29e6b615aa  2017-07-18 03:46:35   NaN 0.5
  5   00056f66da29e6b615aa  2017-07-18 03:46:40   16.961000   NaN
  6   00056f66da29e6b615aa  2017-07-19 03:46:45   11.832000   0.5
  7   00056f66da29e6b615aa  2017-07-19 03:46:50   22.741333   NaN
  </code></pre>
  
  <p>The dataframe is sorted by carid, then by timestamp. I am looking to add a column that adds a trip ID so that for every row that has the same car id, and the previous row differs by no more than 5 seconds from the previous, that they get the same ID; rows 0 - 6 should all get ID 0, rows 6 - 7 should get ID 1, etc. </p>
  
  <p>Something like</p>
  
  <pre><code>(df.timestamp.diff(1).astype(int) &gt; 5000000000).astype(int).cumsum()
  </code></pre>
  
  <p>seems to do the job if there were only one carid in the frame, but I don't know how to differentiate it on the carid.</p>
  
  <p>edit: as @RafaelC pointed out, my data sample was inconsistent with my description, I've updated the table.</p>