How to total CSV column?

Viewed 4380

I want to total a column in a CSV file using the python script below. However, I'm getting the following error.

invalid literal for int() with base 10: '7.3'

What is wrong with my script?

import csv

cr = csv.reader(open("companylist.csv","rb"))
cr.next() # to skip the header 

total = 0
for row in cr:  
   total += int(row[2])
   # possibly do other things with data/rows 

print total
3 Answers
Related