<p>尝试使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.DataFrameGroupBy.aggregate.html#pandas-core-groupby-dataframegroupby-aggregate" rel="nofollow noreferrer">^{<cd1>}</a>+<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.join.html#pandas-dataframe-join" rel="nofollow noreferrer">^{<cd2>}</a>:</p>
<pre><code>df = df.join(
df.groupby('statistics')['s_values'].aggregate(['mean', 'min', 'max']),
on='statistics'
)
</code></pre>
<p><code>df</code>:</p>
<pre class="lang-none prettyprint-override"><code> statistics s_values mean min max
year
1999 cigarette use 100 179.000000 100 315
1999 cellphone use 310 312.666667 310 317
1999 internet use 101 179.333333 101 325
1999 alcohol use 100 117.333333 100 144
1999 soda use 215 368.000000 200 689
2000 cigarette use 315 179.000000 100 315
2000 cellphone use 317 312.666667 310 317
2000 internet use 325 179.333333 101 325
2000 alcohol use 108 117.333333 100 144
2000 soda use 200 368.000000 200 689
2001 cigarette use 122 179.000000 100 315
2001 cellphone use 311 312.666667 310 317
2001 internet use 112 179.333333 101 325
2001 alcohol use 144 117.333333 100 144
2001 soda use 689 368.000000 200 689
</code></pre>
<hr/>
<p>使用的框架:</p>
<pre><code>df = pd.DataFrame({
'year': [1999, 1999, 1999, 1999, 1999, 2000, 2000, 2000, 2000, 2000, 2001,
2001, 2001, 2001, 2001],
'statistics': ['cigarette use', 'cellphone use', 'internet use',
'alcohol use', 'soda use',
'cigarette use', 'cellphone use', 'internet use',
'alcohol use', 'soda use',
'cigarette use', 'cellphone use', 'internet use',
'alcohol use', 'soda use'],
's_values': [100, 310, 101, 100, 215, 315, 317, 325, 108, 200, 122, 311,
112, 144, 689]
}).set_index('year')
</code></pre>