So I am importing a csv file to textfile and the first column is product names and the second is a description of each. I am trying to find the sum of all descriptions using sum(c.values)). Here is my code so far:
import csv import json import sys #from sys import argv from collections import defaultdict from collections import Counter #script, filename = argv data = defaultdict(list) counted_data = defaultdict(list) grouped_data = defaultdict(list) class dictionary: with open ('weekly_20160102.csv', 'rb') as f: reader = csv.reader(f) next(reader, None) for row in reader: data[row[2]].append(row[3]) #this appends the description(value) to the product name(key) #new_item = {} for key in data.keys(): #print key c = Counter(data[key]) for value in c: #print c[value] if c[value] >= 5: print key, ':', value, ':', c[value] elif c[value] <= 1: print 'other', ':', sum(c.values()) Please help!! _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor