我试图解决以下问题:Complete the function sumRows so that it reads a file of this format
and returns a dictionary whose keys specify the names and whose values
are the sum of numerical values in the corresponding row. For example,
the record above would result in an entry 'dave': 14.0. Empty or
non-numerical fields (other than the names in the first column) should
be ignored.
我下面的代码尝试似乎不起作用,我不确定我完全理解这个问题。在def sumRows(filename, header=False):
d ={}
with open(filename) as csvfile:
headerline = csvfile.next()
total = 0
for row in csv.reader(csvfile):
total += int(row[1])
print(total)
对于csv文件rows1
dave,3,5,6
tina,12,3,5