adding values from a csv column and getting the mean. beginner help

brian cleere briancleere at
Wed Dec 11 20:10:00 CET 2013

I know the problem is with the for loop but don't know how to fix. Any help with explanation would be appreciated.

#!/bin/env python
import csv
import sys

if len(sys.argv) < 3:
    print('Please specify a filename and column number: {} [csvfile] [column]'.format(sys.argv[0]))

filename = sys.argv[1]
column = int(sys.argv[2])

for line in filename() , column ():
    elements = line.strip().split(',')

csum = sum(values)
cavg = sum(values)/len(values)
print("Sum of column %d: %f" % (col, csum))
print("Avg of column %d: %f" % (col, cavg))

More information about the Python-list mailing list