count the frequency that a value occurs in a dataframe column

后端 未结 13 1882
耶瑟儿~
耶瑟儿~ 2020-11-22 03:29

I have a dataset

|category|
cat a
cat b
cat a

I\'d like to be able to return something like (showing unique values and frequency)



        
13条回答
  •  时光说笑
    2020-11-22 04:20

    df.category.value_counts()
    

    This short little line of code will give you the output you want.

    If your column name has spaces you can use

    df['category'].value_counts()
    

提交回复
热议问题