title: Pandas dataframe groupby function usage
body: <p>I have pandas df in which I am trying to group it by <code>'agr_group'</code>. <code>'agr_group'</code> are just the count of <code>agr_signal</code> using <code>diff</code> and <code>cumsum</code> function. </p>
  
  <pre><code>BeginDate   Consecutive    EndDate  end_price  start_price  total_return   agr_signal  agr_group  
   2018-03-22           14 2018-04-04   0.000838     0.000997     -0.159478   -1        1.0   
   2018-04-05            2 2018-04-06   0.000738     0.000754     -0.021220   -1        1.0    
   2018-04-07            2 2018-04-08   0.000769     0.000795     -0.032704   -1        1.0    
   2018-04-09            3 2018-04-11   0.000721     0.000713      0.011220    0        2.0   
   2018-04-12            9 2018-04-20   0.004812     0.000876      4.493151    1        3.0   
   2018-04-21           13 2018-05-03   0.004045     0.004250     -0.048235   -1        4.0
  </code></pre>
  
  <p>I am trying to group my df again using following code,</p>
  
  <pre><code>df1 = pd.DataFrame({'BeginDate1' : df.groupby('agr_group').BeginDate.first(), 
                'EndDate1' : df.groupby('agr_group').BeginDate.last(),
                'Consecutive1' : df.groupby('agr_group').size(),
                          'start_price1':df.groupby('agr_group').start_price.first(),
                          'end_price1':df.groupby('agr_group').start_price.last()}).reset_index(drop=True)
  </code></pre>
  
  <p>and the output is,</p>
  
  <pre><code>BeginDate1  Consecutive1   EndDate1  end_price1  start_price1
  2018-03-22             3 2018-04-07    0.000795      0.000997
  2018-04-09             1 2018-04-09    0.000713      0.000713
  2018-04-12             1 2018-04-12    0.000876      0.000876
  2018-04-21             1 2018-04-21    0.004250      0.004250
  </code></pre>
  
  <p>I also want to print the <code>agr_signal</code> as well with occurrence once in <code>agr_signal1</code> column:</p>
  
  <pre><code> BeginDate1    Consecutive1   EndDate1  end_price1  start_price1 agr_signal1
  ----------------------------------------------------------------------------
      2018-03-22             3 2018-04-07    0.000795      0.000997  -1
      2018-04-09             1 2018-04-09    0.000713      0.000713   0 
      2018-04-12             1 2018-04-12    0.000876      0.000876   1
      2018-04-21             1 2018-04-21    0.004250      0.004250  -1
  </code></pre>