pandas 获得列的最频繁值 [英] Pandas get the most frequent values of a column

查看:71
本文介绍了 pandas 获得列的最频繁值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个数据框:

0 name data
1 alex asd
2 helen sdd
3 alex dss
4 helen sdsd
5 john sdadd

so我试图获取 一个或多个最常用的值(在这种情况下为其值)
,所以我要做的是:

so i am trying to get the most frequent value or values(in this case its values) so what i do is:

dataframe['name'].value_counts().idxmax()

,但它只返回值: Alex ,即使 Helen 也出现两次。

but it returns only the value: Alex even if it Helen appears two times as well.

推荐答案

使用模式

df.name.mode()
Out[712]: 
0     alex
1    helen
dtype: object

这篇关于 pandas 获得列的最频繁值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆