How to get unique values with respective occurrence count from a list in Python?

前端 未结 11 2055
孤独总比滥情好
孤独总比滥情好 2020-12-13 13:13

I have a list which has repeating items and I want a list of the unique items with their frequency.

For example, I have [\'a\', \'a\', \'b\', \'b\', \'b\']

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 14:00

    Convert any data structure into a pandas series s:

    CODE:

    for i in sort(s.value_counts().unique()):
      print i, (s.value_counts()==i).sum()
    

提交回复
热议问题