In [7]:
from pandas import DataFrame, read_csv

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

pd.set_option('display.line_width', 5000) 
pd.set_option('display.max_columns', 60) 

%matplotlib inline

In [9]:
# Read in the data
Location = "data/Campaign_Finance_-_FPPC_Form_460_-_Schedule_A_-_Monetary_Contributions.csv"
df = read_csv(Location)

# Convert dollars contributed to a float
df['Tran_Amt1'] = df['Tran_Amt1'].str[1:].astype(float)

# Remove all non-mayor race contributions
mayor_ids = ['1357609', '1354678', '1362261', '1359017']
df = df[df['Filer_ID'].isin(mayor_ids)]

In [10]:
# Sum by recipient and contributor
totals = df.groupby(['Filer_NamL', 'Tran_Emp']).sum()

# Sort each recipient group
sort_amt = lambda x: x.sort('Tran_Amt1', ascending=False)
candidate_max = totals.groupby(level=0).apply(sort_amt)

#candidate_max.groupby(level=0).apply(lambda x: x[:10]).reset_index([0,1], drop=True)['Tran_Amt1']

In [11]:
def aggregate(x):
    Dollars = x['Tran_Amt1'].sum()
    Contributors = x['Tran_Amt1'].count()
    return pd.Series([Dollars, Contributors], index=['Dollars', 'Contributors'])
    

# Sum by recipient and contributor
totals = df.groupby(['Filer_NamL', 'Tran_Emp']).apply(aggregate)
#agg({'Tran_Amt1' : np.sum,
#Tran_Amt2' : np.count_nonzero})

# Sort each recipient group
sort_amt = lambda x: x.sort('Dollars', ascending=False)
candidate_max = totals.groupby(level=0).apply(sort_amt)

candidate_max.groupby(level=0).apply(lambda x: x[:10]).reset_index([0,1], drop=True)


Out[11]:
Dollars Contributors
Filer_NamL Tran_Emp
Joe Tuman for Mayor 2014 Retired 28585 114
Self employed 15850 53
A B & I Foundary 5600 8
Mechanics Bank 3250 4
SKC Communication Products 2100 2
Mills College 1900 3
Self-employed 1900 3
Reed Smith 1700 2
Starr Finley 1400 2
Piedmont USD 1400 1
Libby Schaaf for Oakland Mayor 2014 Retired 6350 15
none 5000 8
retired 3550 10
None 2100 3
SF Regional Center 2100 3
Terra Tech 1400 2
Mark Borsuk Inc. 1400 2
n/a 1400 2
City and County of San Francisco 1400 2
San Francisco Regional Center 1400 2
Parker for Oakland Mayor 2014 Vaquero Capital 2100 3
DaVita 1900 7
IBM 1500 4
The Lapham Company Inc. 1400 3
Reed Smith 1400 3
American City Pest & Termite 1400 2
Fred Thompson Executive Search 1400 2
Wendel Rosen Black & Dean 1400 2
AE3 Partners 1400 2
Braddock & Logan 1400 2
Re-Elect Mayor Quan 2014 retired 13495 66
Lawrence Berkeley National Laboratory 1799 4
Old Republic Title Company 1400 2
not employed 1400 2
Shorenstein Properties LLC 1050 3
City of Oakland 1000 7
United Health Group 800 2
Pacific Life Insurance Company 700 1
Store Development 700 1
Neural ID 700 1

40 rows × 2 columns


In [11]:


In [ ]: