title: Pandas GroupBy.apply method duplicates first group
body: <p>My first SO question:
  I am confused about this behavior of apply method of groupby in pandas (0.12.0-4), it appears to apply the function TWICE to the first row of a data frame. For example:</p>
  <pre><code>&gt;&gt;&gt; from pandas import Series, DataFrame
  &gt;&gt;&gt; import pandas as pd
  &gt;&gt;&gt; df = pd.DataFrame({'class': ['A', 'B', 'C'], 'count':[1,0,2]})
  &gt;&gt;&gt; print(df)
     class  count  
  0     A      1  
  1     B      0    
  2     C      2
  </code></pre>
  <p>I first check that the groupby function works ok, and it seems to be fine:</p>
  <pre><code>&gt;&gt;&gt; for group in df.groupby('class', group_keys = True):
  &gt;&gt;&gt;     print(group)
  ('A',   class  count
  0     A      1)
  ('B',   class  count
  1     B      0)
  ('C',   class  count
  2     C      2)
  </code></pre>
  <p>Then I try to do something similar using apply on the groupby object and I get the first row output twice:</p>
  <pre><code>&gt;&gt;&gt; def checkit(group):
  &gt;&gt;&gt;     print(group)
  &gt;&gt;&gt; df.groupby('class', group_keys = True).apply(checkit)
    class  count
  0     A      1
    class  count
  0     A      1
    class  count
  1     B      0
    class  count
  2     C      2
  </code></pre>
  <p>Any help would be appreciated! Thanks.</p>
  <p>Edit: @Jeff provides the answer below. I am dense and did not understand it immediately, so here is a simple example to show that despite the double printout of the first group in the example above, the apply method operates only once on the first group and does not mutate the original data frame:</p>
  <pre><code>&gt;&gt;&gt; def addone(group):
  &gt;&gt;&gt;     group['count'] += 1
  &gt;&gt;&gt;     return group
  
  &gt;&gt;&gt; df.groupby('class', group_keys = True).apply(addone)
  &gt;&gt;&gt; print(df)
  
        class  count
  0     A      1
  1     B      0
  2     C      2
  </code></pre>
  <p>But by assigning the return of the method to a new object, we see that it works as expected:</p>
  <pre><code>&gt;&gt;&gt; df2 = df.groupby('class', group_keys = True).apply(addone)
  &gt;&gt;&gt; print(df2)
  
        class  count
  0     A      2
  1     B      1
  2     C      3
  </code></pre>