In [80]:
from pandas import DataFrame, read_csv

import matplotlib.pyplot as plt
import pandas as pd

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

%matplotlib inline

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

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

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

In [193]:
# Sum contributions from a single donor (or couple) to a single campaign 
# into one line
Columns = ['Filer_NamL', 'Tran_Amt1']
candidate_totals = df.groupby(['Filer_NamL', 'Tran_NamF', 'Tran_NamL']).sum()
top_totals = candidate_totals
# top_totals = candidate_totals.sort(['Tran_Amt1'], ascending=False)
top_totals['Tran_Amt1'].head(5)


Out[193]:
Filer_NamL                Tran_NamF  Tran_NamL
Joe Tuman for Mayor 2014  Abe        Feinberg     100
                          Adam       Cohen        700
                          Alan       Koch         500
                          Alecto     Caldwell     700
                          Allan      Chan         250
Name: Tran_Amt1, dtype: float64

In [197]:
# Find the max donor to each campaign
f = lambda x: x.sort('Tran_Amt1', ascending=False)
candidate_max_donor = top_totals.groupby(level=0).apply(f).head(3)
candidate_max_donor['Tran_Amt1']


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-197-1116ae3eb1ae> in <module>()
      1 # Find the max donor to each campaign
----> 2 candidate_max_donor = top_totals.groupby(level=0).sort('Tram_Amt1').head(3)
      3 candidate_max_donor['Tran_Amt1']

TypeError: 'bool' object is not callable

In [ ]: