如何计算所有唯一项目

时间:2019-10-18 01:38:55

标签: python

我已附上

enter image description here 我要:该项目的唯一名称列表及其频率计数(基于频率计数的降序)。使用python 例:                                           苹果:(23)                                           香蕉:(16)                                           奶酪:(9)

2 个答案:

答案 0 :(得分:1)

from collections import Counter

Counter(list_you_want_to_count)

collections.Counter

答案 1 :(得分:1)

在furas评论中, 使用熊猫阅读电子表格并调用value_count。

import pandas as pd

# Here you would read in your spreadsheet
items = ['Apples','Bananas','Mushrooms','Tomatoes','Apples','Apples','Tomatoes']
ser = pd.Series(items)

# This gives you list output
ser.value_counts()
##Apples       3
##Tomatoes     2
##Mushrooms    1
##Bananas      1