Expenditures

Total up the expenditures by each committee


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()


<class 'pandas.core.frame.DataFrame'>
Int64Index: 370 entries, 0 to 369
Data columns (total 14 columns):
calaccess_committee_id     370 non-null int64
committee_name_x           370 non-null object
prop_count                 370 non-null int64
committee_name_y           370 non-null object
calaccess_filing_id        370 non-null int64
date_filed                 370 non-null object
from_date                  370 non-null object
thru_date                  370 non-null object
payments_made              370 non-null float64
loans_made                 370 non-null float64
unpaid_bills               370 non-null float64
nonmonetary_adjustment     370 non-null float64
subtotal_cash_payments     370 non-null float64
total_expenditures_made    370 non-null float64
dtypes: float64(6), int64(3), object(5)
memory usage: 43.4+ KB

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)