<p>一次就把他们都弄到手了。在</p>
<pre><code>df.groupby('Age').Raitings.idxmin().str[-1]
Age
1 4
18 1
25 4
45 4
60 1
Name: Raitings, dtype: int64
</code></pre>
<p>如果您想要一个函数,我可以使用<a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.xs.html" rel="nofollow noreferrer"><strong>^{<cd1>}</strong></a>(xs表示横截面)。<br/>
默认情况下,<code>xs</code>将从索引的第一个级别抓取,然后删除该级别。这就方便地离开了我们想要绘制<code>idxmin</code>将要给我们的值的级别。在</p>
^{pr2}$
<hr/>
<p><strong>设置</strong><br/>
对那些试图解析这些东西的人很有用。在</p>
<pre><code>txt = """\
Age Movie User Raitings
1.0 1 4.666667 7.666667
2 4.666667 8.000000
3 2.000000 7.500000
4 2.000000 5.500000
5 3.000000 7.000000
18.0 1 3.000000 7.500000
2 3.000000 8.000000
3 3.000000 8.500000
25.0 1 8.000000 7.250000
2 8.000000 7.500000
3 5.500000 8.500000
4 5.000000 7.000000
45.0 1 9.000000 7.500000
2 9.000000 7.500000
3 11.000000 7.000000
4 11.000000 6.000000
60.0 1 8.000000 7.000000
2 8.000000 9.000000"""
df = pd.read_fwf(pd.io.common.StringIO(txt))
df = df.ffill(downcast='infer').set_index(['Age', 'Movie'])
</code></pre>