Vernon

working in class on the vernon data

In [1]:
lines = open('vernon_1850.csv').readlines()
In [7]:
ages = []
for line in lines[1:]:
    fields = line.split(',')
    age = fields[-1].strip()
    ages.append(eval(age))
In [9]:
average = sum(ages) / len(ages)
average
Out[9]:
25.40448639870077
In [25]:
# This is one way to use the built-in python csv

import csv
csvfile = open('vernon_1850.csv')
reader = csv.DictReader(csvfile)     # an object that you loop over
ages = [eval(line['age']) for line in reader]
sum(ages) / len(ages)
Out[25]:
25.40448639870077
In [ ]: