title: Calculate duration by rotating array from group dataset
body: <p>I hope you could help me with this. I would like to calculate the duration using python.</p>
  
  <p>The data looks like this</p>
  
  <pre><code>group_id, id, departure_time, arrival_time
  1,1,61200,61800
  1,2,18000,18600
  2,1,32400,34200
  2,2,64800,66600
  2,3,77400,81000
  </code></pre>
  
  <p>The result that I would like to get</p>
  
  <pre><code>group_id,id,departure_time, arrival time, departure_rotate, duration
  1,1,61200,61800, 18000, 43800
  1,2,18000,18600,61200,43800
  2,1,32400,34200,77400,43200
  2,2,64800,66600,64800, 1800
  2,3,77400,81000,32400,48600
  </code></pre>
  
  <p>Actually, duration = arrival_time - departure_rotate. However for minus result should be added (24*3600). Thanks in advance. I tried this so far but did not give the expected result. So I think the way that I ask will help.</p>
  
  <pre><code>df_duration = pd.DataFrame(df_trips[[
          "group_id", "id", "arrival_time"
      ]], copy = True)
   df_following = pd.DataFrame(df_trips[[
          "group_id", "id", "departure_time"
      ]], copy = True)
  
      df_following.columns = ["group_id", "id", "following_trip_departure_time"]
      df_following["trip_id"] = df_following["id"] - 1
  
  df_duration = pd.merge(df_duration, df_following, on = ["group_id", "id"])
  </code></pre>