In [4]:
import os
import settings
import pandas as pd
In [46]:
committees = pd.read_csv(os.path.join(settings.data_dir, 'committees-2016.csv'))
In [71]:
positions = pd.read_csv(os.path.join(settings.data_dir, 'committees-and-props-2016.csv'))[
['calaccess_prop_id', 'prop_name', 'calaccess_committee_id', 'committee_position']
]
In [48]:
filings = pd.read_csv(os.path.join(settings.data_dir, "filings-2016.csv"))
In [61]:
merged = committees.merge(
filings,
how="inner",
on="calaccess_committee_id"
)
In [62]:
merged.info()
In [63]:
ctotals = merged.groupby([
'calaccess_committee_id',
'committee_name_x'
]).total_expenditures_made.sum().reset_index()
In [68]:
ctotals.rename(columns={"committee_name_x": "committee_name"}, inplace=True)
In [73]:
c2p = ctotals.merge(positions, on="calaccess_committee_id")
In [75]:
c2ptotals = c2p.groupby([
'prop_name',
'calaccess_committee_id',
'committee_name',
'committee_position'
]).total_expenditures_made.sum().reset_index()
In [78]:
c2ptotals = c2ptotals.sort_values("total_expenditures_made", ascending=False).sort_values("committee_name")
In [79]:
c2ptotals.to_csv(os.path.join(settings.data_dir, 'committee-expenditures-2016.csv'), index=False)
In [80]:
ptotals = c2ptotals.groupby(['prop_name', 'committee_position']).total_expenditures_made.sum().reset_index()
In [81]:
ptotals.to_csv(os.path.join(settings.data_dir, 'proposition-expenditures-2016.csv'), index=False)