The 2016 election is rapidly approaching and one of the major issues of this years race is campaign fiance reform. I am not big into politics, but I am well aware of the Citizens United vs FEC ruling. One thing I do not know however is on what scale politicians actually receive donations. I set out to see how much an average senator or congressman actually receives in a given year.
My intuition led me to believe that these men and women were pulling millions of dollars each year in donations, but that may be based on watching a little to much House of Cards. First thing I needed was the data. Luckily for me all politicians at the state level are required to file info on their finances. Even luckier for me there is an amazing website that databases it all and has an easy to use APIFollowthemoney.orgFirst I wanted to start at the state level, looking at state senators and assemblymen. My guess was that these people were not pulling in the big bucks when it came to campaign donations. I downloaded a data set from follow the money which contained records of donations to lawmakers in the state of New Jersey. From there I cleaned it up and visualized it. Heads up lots of bar charts coming!New Jersey leaning democratic I expect the democrats to pull in a little more money than the republicans.


""" @author: Marcello Campaign Donation NJ totals data sourced from: followthemoney.com goal of program is to breakdown campaign donations to NJ Senators and Congressmen who are currently in office. """ import pandas as pd import matplotlib.pyplot as plt import numpy as np import seaborn as sns def summarytablegen(variable_list,varname): index = np.arange(len(variable_list)) donation_summary2=pd.DataFrame(columns=columns_4_summary, index=index) donation_total={} total_year = 0 i=0 for variable in variable_list: for year in election_year: df1=df.loc[(df['Election_Year'] == year )& (df[varname] == variable)] total_donation = df1['Total_$'].sum() donation_total[str(year)] = total_donation total_year = total_year+total_donation donation_total['Variable']=variable donation_total['Grand Total']=total_year donation_summary2.loc[i] = pd.Series(donation_total) i=i+1 donation_total={} total_year = 0 return donation_summary2 # data preprocessing, removing unnecessary columns df = pd.DataFrame.from_csv('NJlegDon.csv') df=df.reset_index() column_names = df.columns.values.tolist() columns_to_drop = ['request','Election_Year:token','Election_Year:id','Lawmaker:token', 'Office:token','Office:id','General_Office:token','General_Office:id', 'General_Party:token','General_Party:id','Contributor:token','Type_of_Contributor:token', 'Type_of_Contributor:id','General_Industry:token','Broad_Sector:token','In-Jurisdiction:token', 'In-Jurisdiction:id','#_of_Records'] df = df.drop(columns_to_drop, 1) # drop all negative donations df = df[df['Total_$'] >= 0] # %%find total donations for canidate by year Lawmaker_Id = list(set(df['Lawmaker'].tolist())) election_year = list(set(df['Election_Year'].tolist())) Industry = list(set(df['General_Industry'].tolist())) party = list(set(df['General_Party'].tolist())) office= list(set(df['General_Office'].tolist())) str1 =','.join(str(e) for e in election_year) str1=str1.split(',') columns_4_summary = ['Variable','Grand Total'] columns_4_summary.extend(str1) dflawmaker=summarytablegen(Lawmaker_Id,'Lawmaker') dfIndustry=summarytablegen(Industry,'General_Industry') dfparty = summarytablegen(party,'General_Party') dfoffice = summarytablegen(office,'General_Office') #%% # breakdown by party party = pd.melt(dfparty, id_vars=['Variable'], value_vars=str1,var_name='year', value_name='Donations') colors = ["windows blue", "red"] ax = sns.barplot(x="year", y="Donations",hue="Variable", data=party,palette=sns.xkcd_palette(colors)) ax.set( ylabel='Donation Total')