-
-
Save rebeccawilliams/37f70892d637b14a738c to your computer and use it in GitHub Desktop.
for Eric Mill's entertainment
This file contains hidden or 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
| # requires http://unitedstates.sunlightfoundation.com/legislators/legislators.csv | |
| import csv | |
| lawmakers = open("legislators.csv") | |
| men = open("malelegislators.csv","w") | |
| read_file = csv.reader(lawmakers) | |
| write_file = csv.writer(men) | |
| house_men = 0 | |
| house_women = 0 | |
| sen_men = 0 | |
| sen_women = 0 | |
| dem_men = 0 | |
| dem_women = 0 | |
| repub_men = 0 | |
| repub_women = 0 | |
| read_file.next() | |
| for line in read_file: | |
| if int(line[9]) == 1: # alt: if line[9].strip() == '1': | |
| if line[10] == 'M': | |
| if line[0].strip() == 'Rep': | |
| house_men += 1 # shorthand to men = men + 1 | |
| if line[6].strip() == 'D': | |
| dem_men += 1 | |
| elif line[6].strip() == 'R': | |
| repub_men += 1 | |
| elif line[0].strip() == 'Sen': | |
| sen_men += 1 | |
| if line[6].strip() == 'D': | |
| dem_men += 1 | |
| elif line[6].strip() == 'R': | |
| repub_men += 1 | |
| else: | |
| if line[0].strip() == 'Rep': | |
| house_women += 1 | |
| if line[6].strip() == 'D': | |
| dem_women += 1 | |
| elif line[6].strip() == 'R': | |
| repub_women += 1 | |
| elif line[0].strip() == 'Sen': | |
| sen_women += 1 | |
| if line[6].strip() == 'D': | |
| dem_women += 1 | |
| elif line[6].strip() == 'R': | |
| repub_women += 1 | |
| print "There are %s men in the house and only %s women! Ratio of women: %.2f" \ | |
| % (house_men, house_women, float(house_women)/(house_women + house_men)) | |
| print "There are %s men in the senate and only %s women! Ratio of women: %.2f" \ | |
| % (sen_men, sen_women, float(sen_women)/(sen_women + sen_men)) | |
| print "Can you believe there are %s women Republicans in the United States?? (Oh and %s male Republicans!!)" % (repub_women, repub_men) | |
| print "Can you believe there are %s women Democrats in the United States?? (Oh and %s male Democrats!!)" % (dem_women, dem_men) | |
| print "That's %s Republican women and %s Democrat women, making %s women total folks, unbelievable." % (repub_women, dem_women, house_women + sen_women) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment