count the frequency that a value occurs in a dataframe column

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

    If your DataFrame has values with the same type, you can also set return_counts=True in numpy.unique().

    index, counts = np.unique(df.values,return_counts=True)

    np.bincount() could be faster if your values are integers.

    0 讨论(0)
提交回复
热议问题