title: How to calculate the distance covered since event==1 for every ID
body: <p>I want to calculate the distance covered since the variable <code>event</code> was equal to 1. What is important is that the distance should be calculated for every ID.</p>
  
  <p>My dataset consists of a <code>date</code>, <code>car_id</code>, <code>latitude</code>, <code>longitude</code> and a dummy variable indicating event or not. The formula I am using for calculating the distance is:</p>
  
  <pre><code>def Distance(Latitude, Longitude, LatitudeDecimal, LongitudeDecimal):
    az12,az21,dist = wgs84_geod.inv(Longitude, Latitude, LongitudeDecimal, LatitudeDecimal)
    return dist
  </code></pre>
  
  <p>What I want is a calculation of the distance between the two geo-points since the last <code>event==1</code> for every <code>car_id</code>, hence the column <code>distance_since_event</code>:</p>
  
  <pre><code>date    car_id  latitude    longitude   event   distance_since_event
  01/01/2019  1   43.5863 7.12993 0   -1
  01/01/2019  2   44.3929 8.93832 0   -1
  02/01/2019  1   43.5393 7.03134 1   -1
  02/01/2019  2   39.459462   -0.312280   0   -1
  03/01/2019  1   44.3173 84.942  0   calculation=(distance from 02/01/2019-03/01/2019 for ID=1)
  03/01/2019  2   -12.3284    -9.04522    1   -1
  04/01/2019  1   -36.8414    17.4762 0   calculation=(distance from 02/01/2019-04/01/2019 for ID=1)
  04/01/2019  2   43.542  10.2958 0   calculation=(distance from 03/01/2019-04/01/2019 for ID=2)
  05/01/2019  1   43.5242 69.473  0   calculation=(distance from 02/01/2019-05/01/2019 for ID=1)
  05/01/2019  2   37.9382 23.668  1   calculation=(distance from 03/01/2019-05/01/2019 for ID=2)
  06/01/2019  1   4.4409  89.218  1   calculation=(distance from 02/01/2019-06/01/2019 for ID=1)
  06/02/2019  2   25.078037   -77.328900  0   calculation=(distance from 05/01/2019-06/01/2019 for ID=2)
  </code></pre>