I'm trying to make a sum of a column in a csv file. The file looks like:
Date Value
2012-11-20 12
2012-11-21 10
2012-11-22 3
This can be in the range of hundreds of rows. I need to get the total of Value (in this case it would be 25) printed on to a terminal. I so far have some code but it's resulting in a much smaller figure than it should sum. When troubleshooting it, I did a print of the sum and realized that instead of summing 12 + 10 + 3, it actually breaks the numbers in each column and sums as 1 + 2 + 1 + 0 + 3, which obviously equals to a much smaller total. Here's my code, if someone could make a recommendation would be great!
with open("file.csv")) as fin:
headerline = fin.next()
total = 0
for row in csv.reader(fin):
print col # for troubleshooting
for col in row[1]:
total += int(col)
print total