Using groupby group names in function
<p>I have data something like:</p>

<pre><code>df = pd.DataFrame({'user': np.random.choice(['a', 'b','c'], size=100, replace=True),
                   'value1': np.random.randint(10, size=100),
                   'value2': np.random.randint(20, size=100)})
</code></pre>

<p>I'm using it to produce some results, e.g.,</p>

<pre><code>grouped = df.groupby('user')
results = pd.DataFrame()
results['value2_sum'] = grouped['value2'].sum()
</code></pre>

<p>For one of he columns of this result dataframe, I'd like to pass the user names to a different function, which uses data outside of the dataframe.</p>

<p>I tried something like:</p>

<pre><code>results['user_result'] = grouped.apply(lambda x: my_func(x.index))
</code></pre>

<p>But couldn't figure out a syntax that worked.</p>