<p>我有这个数据框:</p>
<pre><code>0 name data
1 alex asd
2 helen sdd
3 alex dss
4 helen sdsd
5 john sdadd
</code></pre>
<p>所以我试图得到最频繁的值(在本例中是它的值)</em></strong>
所以我要做的是:</p>
<pre><code>dataframe['name'].value_counts().idxmax()
</code></pre>
<p>但它只返回值:<strong>Alex</strong>即使它<strong>Helen</strong>也出现了两次。</p>
<p>要获取<code>n</code>最常见的值,只需子集<code>.value_counts()</code>并获取索引:</p>
<pre><code># get top 10 most frequent names
n = 10
dataframe['name'].value_counts()[:n].index.tolist()
</code></pre>