Skip to content

Instantly share code, notes, and snippets.

@ericlagergren
Created July 4, 2014 00:23
Show Gist options
  • Save ericlagergren/edc4a4f714d1a7ea30d6 to your computer and use it in GitHub Desktop.
Save ericlagergren/edc4a4f714d1a7ea30d6 to your computer and use it in GitHub Desktop.
import csv
import datetime
ld = '' # Input wanted LD
legdistrict = []
reader = csv.DictReader(open('active.txt', 'rb'), delimiter='\t')
for row in reader:
if row['LegislativeDistrict'] == 'ld':
legdistrict.append(row)
ages = []
for i,value in enumerate(legdistrict):
dates = datetime.datetime.now() - datetime.datetime.strptime(value['Birthdate'], '%m/%d/%Y')
ages.append(int(datetime.timedelta.total_seconds(dates) / 31556952))
total_values = len(ages)
average_age = sum(ages) / total_values
print average_age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment