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

posted on 2020-10-22 09:45  飞翔的南瓜  阅读(19267)  评论(0编辑  收藏  举报

导航