text_html_output_1.png
import pandas as pd

poll = pd.read_csv('../input/2016-general-election-trump-vs-clinton.csv')

poll = poll.drop(['Pollster URL', 'Source URL', 'Partisan', 'Question Text', 'Question Iteration'], axis=1)

average = pd.DataFrame(poll.mean())
average.drop('Number of Observations', inplace=True)
average

std = pd.DataFrame(poll.std())
std.drop('Number of Observations', inplace=True)
std

poll_avg = pd.concat([average, std], axis=1)
poll_avg.column = ['Average', 'STD']
poll_avg

donor = pd.read_csv('../input/Donor_Data.csv')

donor.drop(donor[donor.contb_receipt_amt < 0].index, inplace=True)

candidates = donor.cand_nm.unique()
candidates

party_map = {'Rubio, Marco': 'Republican', 'Santorum, Richard J.': 'Republican', 'Perry, James R. (Rick)': 'Republican', 'Carson, Benjamin S.': 'Republican', "Cruz, Rafael Edward 'Ted'": 'Republican', 'Paul, Rand': 'Republican', 'Clinton, Hillary Rodham': 'Democrat'}
donor['Party'] = donor.cand_nm.map(party_map)

donor.groupby('cand_nm')['contb_receipt_amt'].count()

donor.groupby('cand_nm')['contb_receipt_amt'].sum()

cand_amount = donor.groupby('cand_nm')['contb_receipt_amt'].sum()
i = 0
for don in cand_amount:
    i += 1

occupation = donor.pivot_table('contb_receipt_amt', index='contbr_occupation', columns='Party', aggfunc='sum')
occupation