count the frequency that a value occurs in a dataframe column

后端 未结 13 1894
耶瑟儿~
耶瑟儿~ 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:15

    If you want to apply to all columns you can use:

    df.apply(pd.value_counts)
    

    This will apply a column based aggregation function (in this case value_counts) to each of the columns.

提交回复
热议问题