title: Pandas groupby: coordinates of current group
body: <p>Suppose I have a data frame</p>
  <pre><code>import pandas as pd
  df = pd.DataFrame({'group':['A','A','B','B','C','C'],'score':[1,2,3,4,5,6]})
  </code></pre>
  <p>At first, say, I want to compute the groups' sums of scores. I usually do</p>
  <pre><code>def group_func(x):
      d = {}
      d['sum_scores'] = x['score'].sum()
      return pd.Series(d)
  df.groupby('group').apply(group_func).reset_index()
  </code></pre>
  <p>Now suppose I want to modify <code>group_func</code> but this modification requires that I know the group identity of the current input <code>x</code>. I tried <code>x['group']</code> and <code>x[group].iloc[0]</code> within the function's definition and neither worked.</p>
  <blockquote>
  <p>Is there a way for the function <code>group_func(x)</code> to know the defining coordinates of the current input <code>x</code>?</p>
  </blockquote>
  <p>In this toy example, say, I just want to get:</p>
  <pre><code>pd.DataFrame({'group':['A','B','C'],'sum_scores':[3,7,11],'name_of_group':['A','B','C']})
  </code></pre>
  <p>where obviously the last column just repeats the first one. I'd like to know how to make this last column using a function like <code>group_func(x)</code>. Like: as <code>group_func</code> processes the <code>x</code> that corresponds to group 'A' and generates the value 3 for <code>sum_scores</code>, how do I extract the current identity 'A' within the local scope of <code>group_func</code>?</p>