title: strange error in python pandas apply
body: <p>The following code gives me a <code>keyError: 0</code>.  It works if I remove the <code>[0]</code> part.</p>
  
  <p>Note that what I really wanted to do is to take each sub-dataframe in the group, do some manipulation (that for examples involves calculation between rows and between columns), and return a new dataframe.  It is similar to ddply or data.table groupby operations in R.   </p>
  
  <pre><code>import pandas as pd
  df = pd.DataFrame(dict(a=list('XYXYXYXY'), b=list('AABBCCDD')))
  df.groupby('a').apply(lambda x: x['b'][0])
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>KeyError                                  Traceback (most recent call last)
  &lt;ipython-input-136-7b87ffbc2fd2&gt; in &lt;module&gt;() 
        1 df = pd.DataFrame(dict(a=list('XYXYXYXY'), b=list('AABBCCDD')))
  ----&gt; 2 df.groupby('a').apply(lambda x: x['b'][0])
  </code></pre>