title: Using 'apply' in Pandas (externally defined function)
body: <p>I have a Dataframe, <code>table</code>, that looks like this:</p>
  
  <pre><code>year name     prop     sex  soundex
  1880 John     0.081541 boy  J500
  1880 William  0.080511 boy  W450
  ....
  2008 Elianna  0.000127 girl E450
  </code></pre>
  
  <p>I'm trying to group <code>table</code> by <code>'year'</code>, and access select indices from the column <code>'name'</code> for each group.</p>
  
  <p>My code is as follows (pretend that <code>special_indices</code> is already defined):</p>
  
  <pre><code>def get_indices_func(x):
      name = [x['name'].iloc[y] for y in special_indices]
      return pd.Series(name)
  
  
  table.groupby(by='year').apply(get_indices_func)
  </code></pre>
  
  <p>I got the following error:</p>
  
  <pre><code>/Users/***/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/core/index.pyc in get_value(self, series, key)
      722         """
      723         try:
  --&gt; 724             return self._engine.get_value(series, key)
      725         except KeyError, e1:
      726             if len(self) &gt; 0 and self.inferred_type == 'integer':
  
  KeyError: 1000 
  </code></pre>
  
  <p>What am I doing wrong?  I think I'm not really understanding how apply (and its cousins, aggregate and agg) works. If someone could explain, I'd be ever so grateful!</p>