Skip to content

Instantly share code, notes, and snippets.

@goldenboy
Forked from eyeseast/nominees.py
Created February 27, 2012 21:42
Show Gist options
  • Save goldenboy/1927294 to your computer and use it in GitHub Desktop.
Save goldenboy/1927294 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