Skip to content

Instantly share code, notes, and snippets.

@eyeseast
Created January 4, 2011 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eyeseast/765321 to your computer and use it in GitHub Desktop.
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
#!/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