title: Pandas: difference between groups
body: <p>Hi I have a panda df that looks like the following (not real data)</p>
  
  <pre><code>index   datedjourney   sequence   values
  1       1              1          120
  2       1              1          100
  3       1              2          75
  4       1              3          50
  5       1              3          30
  6       1              3          61
  7       1              4          40
  8       1              4          50 
  9       2              1          86
  10      2              1          40
  11      2              2          70
  </code></pre>
  
  <p>If I group by datedjourney and sequence like this</p>
  
  <pre><code>df.groupby(['datedjourney', 'sequence'])['values']
  </code></pre>
  
  <p>I want to calculate the difference between the last row in a grouping and the first row in the second group so the <code>df</code> would look like the following</p>
  
  <pre><code>index      datedjourney   sequence   values    diff_between_groups
  1           1              1          120          NaN
  2           1              1          100          NaN
  3           1              2          75           -25
  4           1              3          50           -25
  5           1              3          30           NaN
  6           1              3          61           NaN
  7           1              4          40           -21
  8           1              4          50           NaN
  9           2              1          86           NaN
  10          2              1          40           NaN
  11          2              2          70           30.
  </code></pre>
  
  <p>So the values on row 2 and row 3 should be calculated and the difference should be stored in a new column <code>diff_between_groups</code> on row 3. And then the difference between row 3 and 4 etc. And I don't want to calculate the difference between row 8 and 9 because that's a new <code>datedjourney</code>.</p>