pandas 统计某一列中各个值的出现次数


比如说有一个名为 df1 的dataframe
要统计某一列(比如说列名是city)中各个值出现的次数

#可以通过df.colname 来指定某个列,value_counts()在这里进行计数 df2 = df1.city.value_counts() print(df2) 
  • 1
  • 2
  • 3

在这里插入图片描述

还有一个是统计出现的个数: df.nunique(),

df.nunique()
a    4
b    5
c    1
dtype: int64

https://blog.csdn.net/weixin_42389265/article/details/107013720?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM