Created
January 4, 2011 20:05
-
-
Save eyeseast/765321 to your computer and use it in GitHub Desktop.
Aggregate the number of nominees by outcome for each congress since the 107th
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
Aggregate the number of nominees by outcome for each congress since the 107th | |
""" | |
import csv | |
import sys | |
import os | |
from table_fu import TableFu | |
def main(): | |
out = open('noms.csv', 'wb') | |
writer = csv.DictWriter(out, fieldnames=[ | |
'congress', | |
'submitted', | |
'confirmed', | |
'withdrawn', | |
'pending', | |
'expired' | |
]) | |
writer.writerow(dict(zip(writer.fieldnames, writer.fieldnames))) | |
with open('nominations.csv') as f: | |
noms = TableFu(f) | |
for congress in noms.facet_by('congress_id'): | |
row = { | |
'congress' : congress.faceted_on, | |
'submitted' : congress.count(), | |
'confirmed' : congress.filter(status='Confirmed').count(), | |
'withdrawn' : congress.filter(status='Withdrawn').count(), | |
'pending' : congress.filter(status='Pending').count(), | |
'expired' : congress.filter(status='Nomination Expired').count() | |
} | |
writer.writerow(row) | |
out.close() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment