Created
July 4, 2014 00:23
-
-
Save ericlagergren/edc4a4f714d1a7ea30d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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