title: Dataframe group by including first value of another group
body: <p>Here is my simplified example dataframe:</p>
  <pre><code>  timestamp   A  B  C
  
  1422404668   1   1  2
  1422404670   2   2  3
  1422404672  -3   3  4
  1422404674  -4   4  5
  1422404676   5   5  6
  1422404678  -6   6  7
  1422404680  -7   7  8
  1422404680   8   8  9
  </code></pre>
  <p>Is there a way to group by positive and negative values and get first value of each group in column A, mean values of column B (including the first value of next group) and difference between first value of next group and first value of current group for column C as below output</p>
  <p>Expected output:</p>
  <pre><code>timestamp    A  B     C
  1422404668   1  2     2
  1422404672  -3  4     2
  1422404676   5  5.5   1
  1422404678  -6  7     2
  1422404680   8  8     9
  </code></pre>
  <p>Data:</p>
  <pre><code>{'timestamp': [1422404668, 1422404670, 1422404672, 1422404674,
    1422404676, 1422404678, 1422404680, 1422404680],
   'A': [1, 2, -3, -4, 5, -6, -7, 8], 'B': [1, 2, 3, 4, 5, 6, 7, 8], 'C': [2, 3, 4, 5, 6, 7, 8, 9]}
  </code></pre>
  <p>I'm using the below code to get group by and mean values and difference in the group but how to include the first value of next group in mean difference (column B and C)</p>
  <pre><code>m=df['A'].lt(0)
  df.groupby(m.ne(m.shift()).cumsum()).agg(
              {'timestamp': 'first',
               A: 'first',
               B: 'mean',
               C: lambda x: x.iat[-1]-x.iat[0] if len(x) &gt; 1 else x.iat[0]
               }).reset_index(drop=True)
  </code></pre>