我正在尝试计算一组整数。我有一个包含数字的csv文件,我可以读取它,看起来像这样4,245,34,99,340,...
我的目标是返回一个字典,其中键值对的键是csv文件中的整数值,而值是它在列表中出现的次数。我不确定我在做什么错误,请帮忙解决。
allCounts = dict()
rows = csv.reader(open('...csv'), delimiter=',')
for intValue in rows:
intVal = intValue[0]
for intVal, numAppearances in allCounts:
if intVal in allCounts:
allCounts[numAppearances] = allCounts[numAppearances]+1
else:
allCounts[numAppearances] = 1