Imports

In [1]:
import pandas

Read in data

In [2]:
general = pandas.read_csv("2012_general.csv")
primary = pandas.read_csv("2012_primary.csv")
In [3]:
general
Out[3]:
WARD DIVISION TYPE OFFICE NAME PARTY VOTES
0 1 1 A ATTORNEY GENERAL DAVID J FREED REPUBLICAN 2
1 1 1 A ATTORNEY GENERAL KATHLEEN G KANE DEMOCRATIC 6
2 1 1 A ATTORNEY GENERAL MARAKAY J ROGERS LIBERTARIAN 0
3 1 1 A ATTORNEY GENERAL Write In NaN 0
4 1 1 A AUDITOR GENERAL BETSY ELIZABETH SUMMERS LIBERTARIAN 0
5 1 1 A AUDITOR GENERAL EUGENE A DEPASQUALE DEMOCRATIC 6
6 1 1 A AUDITOR GENERAL JOHN MAHER REPUBLICAN 2
7 1 1 A AUDITOR GENERAL Write In NaN 0
8 1 1 A CITY BOND QUESTION NO NO NaN 0
9 1 1 A CITY BOND QUESTION YES SI NaN 0
10 1 1 A No Vote No Vote NaN 0
11 1 1 A PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES BARACK OBAMA DEMOCRATIC 8
12 1 1 A PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES GARY JOHNSON LIBERTARIAN 0
13 1 1 A PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES JILL STEIN GREEN 0
14 1 1 A PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 1
15 1 1 A PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES Write In NaN 0
16 1 1 A PROPOSED CHARTER CHANGE QUESTION 1 NO NO NaN 3
17 1 1 A PROPOSED CHARTER CHANGE QUESTION 1 YES SI NaN 5
18 1 1 A PROPOSED CHARTER CHANGE QUESTION 2 NO NO NaN 1
19 1 1 A PROPOSED CHARTER CHANGE QUESTION 2 YES SI NaN 7
20 1 1 A PROPOSED CHARTER CHANGE QUESTION 3 NO NO NaN 4
21 1 1 A PROPOSED CHARTER CHANGE QUESTION 3 YES SI NaN 4
22 1 1 A REPRESENTATIVE IN CONGRESS - 1ST DISTRICT JOHN FEATHERMAN REPUBLICAN 1
23 1 1 A REPRESENTATIVE IN CONGRESS - 1ST DISTRICT ROBERT A BRADY DEMOCRATIC 7
24 1 1 A REPRESENTATIVE IN CONGRESS - 1ST DISTRICT Write In NaN 0
25 1 1 A REPRESENTATIVE IN THE GENERAL ASSEMBLY - 184TH... WILLIAM F KELLER DEMOCRATIC 8
26 1 1 A REPRESENTATIVE IN THE GENERAL ASSEMBLY - 184TH... Write In NaN 0
27 1 1 A SENATOR IN THE GENERAL ASSEMBLY - 1ST DISTRICT ALFONSO GAMBONE JR REPUBLICAN 2
28 1 1 A SENATOR IN THE GENERAL ASSEMBLY - 1ST DISTRICT LAWRENCE M FARNESE JR DEMOCRATIC 6
29 1 1 A SENATOR IN THE GENERAL ASSEMBLY - 1ST DISTRICT Write In NaN 0
... ... ... ... ... ... ... ...
188685 66 46 P CITY BOND QUESTION YES SI NaN 0
188686 66 46 P No Vote No Vote NaN 0
188687 66 46 P PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES BARACK OBAMA DEMOCRATIC 1
188688 66 46 P PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES GARY JOHNSON LIBERTARIAN 0
188689 66 46 P PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES JILL STEIN GREEN 0
188690 66 46 P PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 1
188691 66 46 P PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES Write In NaN 0
188692 66 46 P PROPOSED CHARTER CHANGE QUESTION 1 NO NO NaN 0
188693 66 46 P PROPOSED CHARTER CHANGE QUESTION 1 YES SI NaN 0
188694 66 46 P PROPOSED CHARTER CHANGE QUESTION 2 NO NO NaN 1
188695 66 46 P PROPOSED CHARTER CHANGE QUESTION 2 YES SI NaN 0
188696 66 46 P PROPOSED CHARTER CHANGE QUESTION 3 NO NO NaN 0
188697 66 46 P PROPOSED CHARTER CHANGE QUESTION 3 YES SI NaN 0
188698 66 46 P REPRESENTATIVE IN CONGRESS - 13TH DISTRICT ALLYSON Y SCHWARTZ DEMOCRATIC 1
188699 66 46 P REPRESENTATIVE IN CONGRESS - 13TH DISTRICT JOSEPH JAMES ROONEY REPUBLICAN 0
188700 66 46 P REPRESENTATIVE IN CONGRESS - 13TH DISTRICT Write In NaN 0
188701 66 46 P REPRESENTATIVE IN THE GENERAL ASSEMBLY - 169TH... DAVID M KRALLE REPUBLICAN 0
188702 66 46 P REPRESENTATIVE IN THE GENERAL ASSEMBLY - 169TH... ED NEILSON DEMOCRATIC 1
188703 66 46 P REPRESENTATIVE IN THE GENERAL ASSEMBLY - 169TH... Write In NaN 0
188704 66 46 P SENATOR IN THE GENERAL ASSEMBLY - 5TH DISTRICT MICHAEL J TOMLINSON REPUBLICAN 0
188705 66 46 P SENATOR IN THE GENERAL ASSEMBLY - 5TH DISTRICT MIKE STACK DEMOCRATIC 1
188706 66 46 P SENATOR IN THE GENERAL ASSEMBLY - 5TH DISTRICT Write In NaN 0
188707 66 46 P STATE TREASURER DIANA IREY VAUGHAN REPUBLICAN 0
188708 66 46 P STATE TREASURER PATRICIA M FRYMAN LIBERTARIAN 0
188709 66 46 P STATE TREASURER ROBERT M MCCORD DEMOCRATIC 1
188710 66 46 P STATE TREASURER Write In NaN 0
188711 66 46 P UNITED STATES SENATOR BOB CASEY JR DEMOCRATIC 1
188712 66 46 P UNITED STATES SENATOR RAYBURN DOUGLAS SMITH LIBERTARIAN 0
188713 66 46 P UNITED STATES SENATOR TOM SMITH REPUBLICAN 1
188714 66 46 P UNITED STATES SENATOR Write In NaN 0

188715 rows × 7 columns

Cleaning up

In [4]:
# get rid of whitespace
general = general.replace({r'\s+':' '},regex=True)
primary = primary.replace({r'\s+':' '},regex=True)

Making sure I understand what a "division" is

I'm pretty sure it's a unique ward/division combination

In [5]:
len((general['WARD'].map(str) + " " + general['DIVISION'].map(str)).unique())
Out[5]:
1687

In this tweet, Godfrey mentions 1686. I'm not sure where my extra one comes from, but I'll consider this close enough.

Where does Hannity's/Philadelphia Inquirer's 59 divisions come from?

Machine, absentee, and provisional together?
In [6]:
gen_sum = general.groupby(['WARD', 'DIVISION', 'OFFICE','NAME','PARTY'])[['VOTES']].sum().add_suffix('_sum').reset_index()
gen_sum_romney = gen_sum[gen_sum.NAME == "MITT ROMNEY"]
gen_sum_romney_none = gen_sum_romney[gen_sum_romney.VOTES_sum == 0]
print 'number of divisions with no A, M, or P votes for Romney: ', len(gen_sum_romney_none)
number of divisions with no A, M, or P votes for Romney:  50
...nope
Just machine and absentee?
In [7]:
gen_AM = general[(general.TYPE == "A") | (general.TYPE == "M")]
gen_AM_sum = gen_AM.groupby(['WARD', 'DIVISION', 'OFFICE','NAME','PARTY'])[['VOTES']].sum().add_suffix('_sum').reset_index()
gen_AM_sum_romney = gen_AM_sum[gen_AM_sum.NAME == "MITT ROMNEY"]
gen_AM_sum_romney_none = gen_AM_sum_romney[gen_AM_sum_romney.VOTES_sum == 0]
print 'number of divisions with no A or M votes for Romney: ', len(gen_AM_sum_romney_none)
number of divisions with no A or M votes for Romney:  55
...nope
Just machine?
In [8]:
gen_machine_romney = general[(general.NAME == "MITT ROMNEY") & (general.TYPE == "M")]
gen_machine_romney_none = gen_machine_romney[gen_machine_romney.VOTES == 0]
print 'number of divisions with no M votes for Romney: ', len(gen_machine_romney_none)
number of divisions with no M votes for Romney:  59
...yup!
In [9]:
gen_machine_romney_none
Out[9]:
WARD DIVISION TYPE OFFICE NAME PARTY VOTES
6886 3 14 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
6991 3 15 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
8176 4 4 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
14104 6 6 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
24101 10 8 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
25505 10 21 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
26480 11 1 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
26714 11 3 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
28586 11 19 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
31057 12 21 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
33109 13 15 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
38609 16 8 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
38726 16 9 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
38960 16 11 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
39194 16 13 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
39545 16 16 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
40001 17 2 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
46267 19 14 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
59842 24 9 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
60640 24 16 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
69410 28 3 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
69760 28 6 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
70219 28 10 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
70789 28 15 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
71938 29 7 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
72166 29 9 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
77233 32 1 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
77461 32 3 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
78619 32 13 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
79303 32 19 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
79417 32 20 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
79987 32 25 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
80215 32 27 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
80443 32 29 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
93992 36 22 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
96250 37 1 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
96706 37 5 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
97048 37 8 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
97504 37 12 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
98597 38 1 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
98831 38 3 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
99416 38 8 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
120091 44 1 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
120205 44 2 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
120319 44 3 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
121801 44 16 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
126384 46 12 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
126717 46 15 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
129140 47 13 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
129257 47 14 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
133960 49 19 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
137867 51 3 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
138518 51 9 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
140486 51 27 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
164888 59 2 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
168167 60 7 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
168501 60 10 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
169382 60 18 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0
169814 60 22 M PRESIDENT AND VICE PRESIDENT OF THE UNITED STATES MITT ROMNEY REPUBLICAN 0

Ok, so let's match those 59 divisions up to primary data

We'll restrict to M types from now on

I'm not exactly sure why, but Philadelphia doesn't give what ballot was used (e.g. Republican or Democratic), only the office and the party of the person voted for. So if we want to get write-in votes counted toward votes in a division, which I think we do, we need to separate the Republican primary votes by race, instead of simply by party of votee. This is a bit cumbersome, but at least the Republican primary races are easily identified as such.

A wrinkle: it looks like primary ballots for both parties include various "SPECIAL ELECTION"s. I did not count these toward either primary, because I couldn't tell which one they belonged to (i.e. a Democrat could've voted for a Republican or vice versa).

In [10]:
primary["OFFICE"].unique()
Out[10]:
array(['ALTERNATE DELEGATE TO THE DEMOCRATIC NATIONAL CONVENTION 1ST DIST',
       'ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 1ST DIST',
       'ATTORNEY GENERAL-DEM', 'ATTORNEY GENERAL-REP',
       'AUDITOR GENERAL-DEM', 'AUDITOR GENERAL-REP',
       'DELEGATE TO THE DEMOCRATIC NATIONAL CONVENTION 1ST DIST',
       'DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 1ST DIST',
       'No Vote', 'PRESIDENT OF THE UNITED STATES-DEM',
       'PRESIDENT OF THE UNITED STATES-REP',
       'REPRESENTATIVE IN CONGRESS - 1ST DIST - DEM',
       'REPRESENTATIVE IN CONGRESS - 1ST DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 184TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 184TH DIST - REP',
       'SENATOR IN THE GENERAL ASSEMBLY - 1ST DIST - DEM',
       'SENATOR IN THE GENERAL ASSEMBLY - 1ST DIST - REP',
       'STATE TREASURER-DEM', 'STATE TREASURER-REP',
       'UNITED STATES SENATOR -DEM', 'UNITED STATES SENATOR -REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 175TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 175TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 182ND DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 182ND DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 186TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 186TH DIST - REP',
       'SPECIAL ELECTION - REPRESENTATIVE IN THE GENERAL ASSEMBLY - 186TH DIST',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 191ST DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 191ST DIST - REP',
       'ALTERNATE DELEGATE TO THE DEMOCRATIC NATIONAL CONVENTION 2ND DIST',
       'ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 2ND DIST',
       'DELEGATE TO THE DEMOCRATIC NATIONAL CONVENTION 2ND DIST',
       'DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 2ND DIST',
       'REPRESENTATIVE IN CONGRESS - 2ND DIST - DEM',
       'REPRESENTATIVE IN CONGRESS - 2ND DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 190TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 190TH DIST - REP',
       'SENATOR IN THE GENERAL ASSEMBLY - 7TH DIST - DEM',
       'SENATOR IN THE GENERAL ASSEMBLY - 7TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 192ND DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 192ND DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 181ST DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 181ST DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 195TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 195TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 180TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 180TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 200TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 200TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 198TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 198TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 203RD DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 203RD DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 197TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 197TH DIST - REP',
       'SENATOR IN THE GENERAL ASSEMBLY - 3RD DIST - DEM',
       'SENATOR IN THE GENERAL ASSEMBLY - 3RD DIST - REP',
       'SPECIAL ELECTION - REPRESENTATIVE IN THE GENERAL ASSEMBLY - 197TH DIST',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 201ST DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 201ST DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 202ND DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 202ND DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 194TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 194TH DIST - REP',
       'ALTERNATE DELEGATE TO THE DEMOCRATIC NATIONAL CONVENTION 13TH DIST',
       'ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 13TH DIST',
       'DELEGATE TO THE DEMOCRATIC NATIONAL CONVENTION 13TH DIST',
       'DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 13TH DIST',
       'REPRESENTATIVE IN CONGRESS - 13TH DIST - DEM',
       'REPRESENTATIVE IN CONGRESS - 13TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 179TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 179TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 177TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 177TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 185TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 185TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 188TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 188TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 154TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 154TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 170TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 170TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 173RD DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 173RD DIST - REP',
       'SENATOR IN THE GENERAL ASSEMBLY - 5TH DIST - DEM',
       'SENATOR IN THE GENERAL ASSEMBLY - 5TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 174TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 174TH DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 172ND DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 172ND DIST - REP',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 169TH DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 169TH DIST - REP',
       'SPECIAL ELECTION - REPRESENTATIVE IN THE GENERAL ASSEMBLY - 169TH DIST',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 152ND DIST - DEM',
       'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 152ND DIST - REP'], dtype=object)
In [11]:
republican_primary_races = [
    'ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 1ST DIST',
    'ATTORNEY GENERAL-REP',
    'AUDITOR GENERAL-REP',
    'DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 1ST DIST',
    'PRESIDENT OF THE UNITED STATES-REP',
    'REPRESENTATIVE IN CONGRESS - 1ST DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 184TH DIST - REP',
    'SENATOR IN THE GENERAL ASSEMBLY - 1ST DIST - REP',
    'STATE TREASURER-REP',
    'UNITED STATES SENATOR -REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 175TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 182ND DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 186TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 191ST DIST - REP',
    'ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 2ND DIST',
    'DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 2ND DIST',
    'REPRESENTATIVE IN CONGRESS - 2ND DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 190TH DIST - REP',
    'SENATOR IN THE GENERAL ASSEMBLY - 7TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 192ND DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 181ST DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 195TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 180TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 200TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 198TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 203RD DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 197TH DIST - REP',
    'SENATOR IN THE GENERAL ASSEMBLY - 3RD DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 201ST DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 202ND DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 194TH DIST - REP',
    'ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 13TH DIST',
    'DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION 13TH DIST',
    'REPRESENTATIVE IN CONGRESS - 13TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 179TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 177TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 185TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 188TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 154TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 170TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 173RD DIST - REP',
    'SENATOR IN THE GENERAL ASSEMBLY - 5TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 174TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 172ND DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 169TH DIST - REP',
    'REPRESENTATIVE IN THE GENERAL ASSEMBLY - 152ND DIST - REP'
                   ]
In [12]:
republican_primary = primary[primary.OFFICE.isin(republican_primary_races)]
In [13]:
relevant_primary = pandas.merge(gen_machine_romney_none[['WARD','DIVISION','TYPE']], republican_primary, on=['WARD','DIVISION','TYPE'], how='inner', suffixes=('_GENERAL', '_PRIMARY'))
relevant_primary
Out[13]:
WARD DIVISION TYPE OFFICE NAME PARTY VOTES
0 3 14 M ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL ... SETH W KAUFER REPUBLICAN 0
1 3 14 M ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL ... THOMAS DANZI REPUBLICAN 0
2 3 14 M ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL ... WILLIAM PETTIGREW REPUBLICAN 0
3 3 14 M ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL ... Write In NaN 0
4 3 14 M ATTORNEY GENERAL-REP DAVID J FREED REPUBLICAN 0
5 3 14 M ATTORNEY GENERAL-REP Write In NaN 0
6 3 14 M AUDITOR GENERAL-REP FRANK A PINTO REPUBLICAN 0
7 3 14 M AUDITOR GENERAL-REP JOHN MAHER REPUBLICAN 0
8 3 14 M AUDITOR GENERAL-REP Write In NaN 0
9 3 14 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... CHRISTOPHER M VOGLER REPUBLICAN 0
10 3 14 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... DALE KERNS REPUBLICAN 0
11 3 14 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... FREDERICK W ANTON REPUBLICAN 0
12 3 14 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... MARION S TAXIN REPUBLICAN 0
13 3 14 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... MICHAEL W UNTERMEYER REPUBLICAN 0
14 3 14 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... TOM BOGGIA REPUBLICAN 0
15 3 14 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... Write In NaN 0
16 3 14 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
17 3 14 M PRESIDENT OF THE UNITED STATES-REP NEWT GINGRICH REPUBLICAN 0
18 3 14 M PRESIDENT OF THE UNITED STATES-REP RICK SANTORUM REPUBLICAN 0
19 3 14 M PRESIDENT OF THE UNITED STATES-REP RON PAUL REPUBLICAN 0
20 3 14 M PRESIDENT OF THE UNITED STATES-REP Write In NaN 0
21 3 14 M REPRESENTATIVE IN CONGRESS - 1ST DIST - REP JOHN FEATHERMAN REPUBLICAN 0
22 3 14 M REPRESENTATIVE IN CONGRESS - 1ST DIST - REP Write In NaN 0
23 3 14 M REPRESENTATIVE IN THE GENERAL ASSEMBLY - 191ST... Write In NaN 0
24 3 14 M STATE TREASURER-REP DIANA IREY VAUGHAN REPUBLICAN 0
25 3 14 M STATE TREASURER-REP Write In NaN 0
26 3 14 M UNITED STATES SENATOR -REP DAVID ALAN CHRISTIAN REPUBLICAN 0
27 3 14 M UNITED STATES SENATOR -REP MARC A SCARINGI REPUBLICAN 0
28 3 14 M UNITED STATES SENATOR -REP SAM ROHRER REPUBLICAN 0
29 3 14 M UNITED STATES SENATOR -REP STEVEN D WELCH REPUBLICAN 0
... ... ... ... ... ... ... ...
1975 60 22 M ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL ... LEWIS F GOULD JR REPUBLICAN 0
1976 60 22 M ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL ... SETH C KOREN REPUBLICAN 0
1977 60 22 M ALTERNATE DELEGATE TO THE REPUBLICAN NATIONAL ... Write In NaN 0
1978 60 22 M ATTORNEY GENERAL-REP DAVID J FREED REPUBLICAN 0
1979 60 22 M ATTORNEY GENERAL-REP Write In NaN 0
1980 60 22 M AUDITOR GENERAL-REP FRANK A PINTO REPUBLICAN 0
1981 60 22 M AUDITOR GENERAL-REP JOHN MAHER REPUBLICAN 0
1982 60 22 M AUDITOR GENERAL-REP Write In NaN 0
1983 60 22 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... ADAM A LANG REPUBLICAN 0
1984 60 22 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... CALVIN R TUCKER REPUBLICAN 0
1985 60 22 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... LEWIS HARRIS JR REPUBLICAN 0
1986 60 22 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... VAHAN H GUREGHIAN REPUBLICAN 0
1987 60 22 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... WALTER F VOGLER JR REPUBLICAN 0
1988 60 22 M DELEGATE TO THE REPUBLICAN NATIONAL CONVENTION... Write In NaN 0
1989 60 22 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1990 60 22 M PRESIDENT OF THE UNITED STATES-REP NEWT GINGRICH REPUBLICAN 0
1991 60 22 M PRESIDENT OF THE UNITED STATES-REP RICK SANTORUM REPUBLICAN 0
1992 60 22 M PRESIDENT OF THE UNITED STATES-REP RON PAUL REPUBLICAN 0
1993 60 22 M PRESIDENT OF THE UNITED STATES-REP Write In NaN 0
1994 60 22 M REPRESENTATIVE IN CONGRESS - 2ND DIST - REP ROBERT ALLEN MANSFIELD JR REPUBLICAN 0
1995 60 22 M REPRESENTATIVE IN CONGRESS - 2ND DIST - REP Write In NaN 0
1996 60 22 M REPRESENTATIVE IN THE GENERAL ASSEMBLY - 190TH... Write In NaN 0
1997 60 22 M STATE TREASURER-REP DIANA IREY VAUGHAN REPUBLICAN 0
1998 60 22 M STATE TREASURER-REP Write In NaN 0
1999 60 22 M UNITED STATES SENATOR -REP DAVID ALAN CHRISTIAN REPUBLICAN 0
2000 60 22 M UNITED STATES SENATOR -REP MARC A SCARINGI REPUBLICAN 0
2001 60 22 M UNITED STATES SENATOR -REP SAM ROHRER REPUBLICAN 0
2002 60 22 M UNITED STATES SENATOR -REP STEVEN D WELCH REPUBLICAN 0
2003 60 22 M UNITED STATES SENATOR -REP TOM SMITH REPUBLICAN 0
2004 60 22 M UNITED STATES SENATOR -REP Write In NaN 0

2005 rows × 7 columns

In [14]:
#this way of joining doesn't allow for write-ins!
#relevant_primary = pandas.merge(gen_machine_romney_none[['WARD','DIVISION','TYPE','PARTY']], primary, on=['WARD','DIVISION','TYPE','PARTY'], how='inner', suffixes=('_GENERAL', '_PRIMARY'))

How many people voted in each division's primary?

Because votes are aggregated at candidate level, but voters can vote in multiple races, we can only place lower and upper bounds on the number of voters. To place a lower bound, we can take the maximum number of votes in any given Republican primary race for each division. To place an upper bound, we can sum the votes for all Republican primary races for each division.

In [15]:
relevant_primary_office = relevant_primary.groupby(['WARD','DIVISION','OFFICE'])[['VOTES']].sum().reset_index()
relevant_primary_office_atleast = relevant_primary.groupby(['WARD','DIVISION'])[['VOTES']].max().reset_index()
print '# of voters, # of divisions with at least that many voters\n',relevant_primary_office_atleast['VOTES'].value_counts()
relevant_primary_office_atleast
# of voters, # of divisions with at least that many voters
0    30
1    13
2    10
3     5
4     1
dtype: int64
Out[15]:
WARD DIVISION VOTES
0 3 14 0
1 3 15 1
2 4 4 0
3 6 6 0
4 10 8 1
5 10 21 0
6 11 1 1
7 11 3 3
8 11 19 0
9 12 21 0
10 13 15 1
11 16 8 0
12 16 9 1
13 16 11 0
14 16 13 0
15 16 16 2
16 17 2 1
17 19 14 0
18 24 9 2
19 24 16 2
20 28 3 0
21 28 6 1
22 28 10 3
23 28 15 0
24 29 7 3
25 29 9 2
26 32 1 2
27 32 3 0
28 32 13 3
29 32 19 1
30 32 20 2
31 32 25 1
32 32 27 1
33 32 29 0
34 36 22 2
35 37 1 0
36 37 5 2
37 37 8 1
38 37 12 0
39 38 1 0
40 38 3 3
41 38 8 0
42 44 1 4
43 44 2 0
44 44 3 2
45 44 16 1
46 46 12 0
47 46 15 0
48 47 13 0
49 47 14 0
50 49 19 0
51 51 3 0
52 51 9 0
53 51 27 0
54 59 2 0
55 60 7 0
56 60 10 1
57 60 18 2
58 60 22 0
In [16]:
relevant_primary_atmost = relevant_primary.groupby(['WARD','DIVISION'])[['VOTES']].sum().reset_index()
print '# of voters, # of divisions with at most that many voters\n',relevant_primary_atmost['VOTES'].value_counts()
relevant_primary_atmost
# of voters, # of divisions with at most that many voters
0     30
8      4
25     3
6      3
1      3
13     2
10     2
5      2
4      2
2      2
42     1
26     1
24     1
22     1
19     1
12     1
dtype: int64
Out[16]:
WARD DIVISION VOTES
0 3 14 0
1 3 15 2
2 4 4 0
3 6 6 0
4 10 8 6
5 10 21 0
6 11 1 6
7 11 3 25
8 11 19 0
9 12 21 0
10 13 15 8
11 16 8 0
12 16 9 8
13 16 11 0
14 16 13 0
15 16 16 13
16 17 2 10
17 19 14 0
18 24 9 13
19 24 16 22
20 28 3 0
21 28 6 6
22 28 10 25
23 28 15 0
24 29 7 5
25 29 9 12
26 32 1 8
27 32 3 0
28 32 13 26
29 32 19 4
30 32 20 19
31 32 25 1
32 32 27 4
33 32 29 0
34 36 22 2
35 37 1 0
36 37 5 8
37 37 8 1
38 37 12 0
39 38 1 0
40 38 3 5
41 38 8 0
42 44 1 42
43 44 2 0
44 44 3 24
45 44 16 10
46 46 12 0
47 46 15 0
48 47 13 0
49 47 14 0
50 49 19 0
51 51 3 0
52 51 9 0
53 51 27 0
54 59 2 0
55 60 7 0
56 60 10 1
57 60 18 25
58 60 22 0

How many people voted in each division's presidential primary?

In [17]:
relevant_primary_prez = relevant_primary[relevant_primary.OFFICE == 'PRESIDENT OF THE UNITED STATES-REP']
relevant_primary_prez_sum = relevant_primary_prez.groupby(['WARD','DIVISION','OFFICE','PARTY'])[['VOTES']].sum().reset_index()
print '# of voters, # of divisions with that many voters\n',relevant_primary_prez_sum['VOTES'].value_counts()
relevant_primary_prez_sum
# of voters, # of divisions with that many voters
0    32
1    14
3     6
2     6
4     1
dtype: int64
Out[17]:
WARD DIVISION OFFICE PARTY VOTES
0 3 14 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
1 3 15 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
2 4 4 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
3 6 6 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
4 10 8 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
5 10 21 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
6 11 1 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
7 11 3 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 3
8 11 19 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
9 12 21 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
10 13 15 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
11 16 8 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
12 16 9 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
13 16 11 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
14 16 13 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
15 16 16 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 3
16 17 2 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
17 19 14 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
18 24 9 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 2
19 24 16 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 2
20 28 3 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
21 28 6 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
22 28 10 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 2
23 28 15 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
24 29 7 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
25 29 9 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
26 32 1 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 2
27 32 3 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
28 32 13 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 3
29 32 19 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
30 32 20 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 3
31 32 25 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
32 32 27 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
33 32 29 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
34 36 22 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 2
35 37 1 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
36 37 5 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
37 37 8 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
38 37 12 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
39 38 1 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
40 38 3 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 3
41 38 8 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
42 44 1 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 4
43 44 2 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
44 44 3 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 2
45 44 16 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
46 46 12 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
47 46 15 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
48 47 13 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
49 47 14 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
50 49 19 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
51 51 3 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
52 51 9 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
53 51 27 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
54 59 2 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
55 60 7 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0
56 60 10 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 1
57 60 18 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 3
58 60 22 PRESIDENT OF THE UNITED STATES-REP REPUBLICAN 0

How many people voted for Romney in each division's presidential primary?

In [18]:
relevant_primary_prez_romney = relevant_primary_prez[relevant_primary_prez.NAME == 'MITT ROMNEY']
print '# of voters, # of divisions with that many voters\n',relevant_primary_prez_romney['VOTES'].value_counts()
relevant_primary_prez_romney
# of voters, # of divisions with that many voters
0    52
1     6
2     1
dtype: int64
Out[18]:
WARD DIVISION TYPE OFFICE NAME PARTY VOTES
16 3 14 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
48 3 15 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
81 4 4 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
115 6 6 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
149 10 8 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
182 10 21 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
215 11 1 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 1
250 11 3 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
285 11 19 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
320 12 21 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
354 13 15 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
388 16 8 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
423 16 9 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
458 16 11 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
493 16 13 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
528 16 16 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 1
563 17 2 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
595 19 14 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
628 24 9 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
662 24 16 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 2
696 28 3 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
731 28 6 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 1
765 28 10 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
799 28 15 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
833 29 7 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
867 29 9 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
901 32 1 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
935 32 3 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
969 32 13 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 1
1003 32 19 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1037 32 20 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1071 32 25 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1105 32 27 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1139 32 29 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1173 36 22 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1208 37 1 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1242 37 5 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1276 37 8 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1310 37 12 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1344 38 1 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1379 38 3 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1414 38 8 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1449 44 1 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 1
1483 44 2 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1517 44 3 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 1
1551 44 16 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1585 46 12 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1619 46 15 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1653 47 13 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1688 47 14 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1723 49 19 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1757 51 3 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1790 51 9 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1823 51 27 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1856 59 2 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1889 60 7 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1922 60 10 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1956 60 18 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0
1989 60 22 M PRESIDENT OF THE UNITED STATES-REP MITT ROMNEY REPUBLICAN 0

Just for fun

Who received the most primary votes in these divisions?

In [19]:
relevant_primary[relevant_primary.OFFICE == "PRESIDENT OF THE UNITED STATES-REP"].groupby(["NAME"])[["VOTES"]].sum().reset_index()
Out[19]:
NAME VOTES
0 MITT ROMNEY 8
1 NEWT GINGRICH 15
2 RICK SANTORUM 11
3 RON PAUL 14
4 Write In 0