In [2]:
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 [3]:
# 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)

In [14]:
# Sum by recipient and contributor
totals = df.groupby(['Filer_NamL', 'Tran_NamF', 'Tran_NamL']).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[:3]).reset_index([0,1], drop=True)['Tran_Amt1']


Out[14]:
Filer_NamL                                                    Tran_NamF  Tran_NamL
Amy Lemley for City Council 2012                              Colleen    Ryan          450
                                                              Susan      Martin        100
                                                              Eric       Martin        100
Barbara Parker City Attorney Officeholder Account             Alex       Katz         1400
                                                              Mark       Morodomi     1400
                                                              Wayne      Nishioka      700
Barbara Parker for Oakland City Attorney 2012                 Geoffrey   Spellberg     NaN
                                                              Steven     Kay           NaN
                                                              Mona       Hanna         700
Committee against Measure A                                   Madeline   Hovland      1751
                                                              Dan        Grassetti    1426
Committee to Elect Don Link to City Council                   Jim        Ratliff       500
                                                              Douglas    Wong          200
                                                              Linda      Hurd          150
Committee to Elect Lynette Gibson-McElhaney for Council 2012  Jasvir     Mand         1400
...
Re-Elect Jumoke Hinton Hodge for Oakland School Board  Greg        Penner           700.00
                                                       Mark        Smith            700.00
Re-Elect Larry Reid for City Council 2012              Zhi         Li               700.00
                                                       Joseph      Chelstowski      700.00
                                                       Jeffery     Mitchell         700.00
Re-Elect Mayor Quan 2014                               Paula       Vu               700.00
                                                       Kikuko      Ito              700.00
                                                       Karina      Cao              700.00
Roseann Torres for Oakland School Board                Martin      Caraves         1400.00
                                                       Robert      Apodaca         1000.00
                                                       Zack        Neumeyer         700.00
The Oakland Fund for Keep Oakland Firesafe 2013        Phillip H.  Tagami          5000.00
                                                       Teresa      Ferguson        2000.00
                                                       Mark        McClure         1000.00
Tolbert for City Council 2012                          Dr. Joel    Tolbert        20509.04
Name: Tran_Amt1, Length: 96, dtype: float64

In [13]:



Out[13]:
<pandas.core.groupby.DataFrameGroupBy object at 0x103642550>

In [ ]: