<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Analysis of CA ballot measure financing
Including Proposition 62 to abolish the death penalty in California.
Step1:  Read in data on committees and contributions
Step2:  Number of committees per proposition
Step3:  Filter for proposition of interest
Step4:  All contributions to all committees for and against the proposition
Step5:  Total contributions
Step6:  Number of committees for and against the proposition
Step7:  Total contributions for the proposition
Step8:  Total contributions against the proposition
Step9:  Percentage of total contributions given to support the proposition
Step10:  Top contributions in support of the proposition
Step11:  Top contributions in opposition to the proposition
Step12:  Total intake, by committee, for and against the proposition
Step13:  Top individual and organizational contributors for and against the proposition
Used fillna() to fill missing (NaN) values for contributors' first and last names
Combination of first name, last name, city and "position" assumed to be unique individual
<ASSISTANT_TASK:>
Python Code:
import pandas as pd
# proposition = "PROPOSITION 064- MARIJUANA LEGALIZATION. INITIATIVE STATUTE."
proposition = "PROPOSITION 062- DEATH PENALTY. INITIATIVE STATUTE."
Explanation: Analysis of CA ballot measure financing
Including Proposition 62 to abolish the death penalty in California.
End of explanation
props = pd.read_csv("http://www.firstpythonnotebook.org/_static/committees.csv")
contribs = pd.read_csv("http://www.firstpythonnotebook.org/_static/contributions.csv")
Explanation: Read in data on committees and contributions
End of explanation
props.prop_name.value_counts()
Explanation: Number of committees per proposition
End of explanation
prop = props[props.prop_name == proposition]
Explanation: Filter for proposition of interest
End of explanation
merged = pd.merge(prop, contribs, on="calaccess_committee_id")
merged[["contributor_firstname", "contributor_lastname", "contributor_city", "contributor_state", "amount", "committee_name_x", "committee_position"]].head()
Explanation: All contributions to all committees for and against the proposition
End of explanation
merged.amount.sum()
Explanation: Total contributions
End of explanation
merged.committee_position.value_counts().reset_index()
support = merged[merged.committee_position == "SUPPORT"]
oppose = merged[merged.committee_position == "OPPOSE"]
Explanation: Number of committees for and against the proposition
End of explanation
support.amount.sum()
Explanation: Total contributions for the proposition
End of explanation
oppose.amount.sum()
Explanation: Total contributions against the proposition
End of explanation
support.amount.sum() / merged.amount.sum()
Explanation: Percentage of total contributions given to support the proposition
End of explanation
support.sort_values("amount", ascending=False)[["contributor_firstname", "contributor_lastname", "contributor_city", "contributor_state", "amount", "committee_name_x"]].head()
Explanation: Top contributions in support of the proposition
End of explanation
oppose.sort_values("amount", ascending=False)[["contributor_firstname", "contributor_lastname", "contributor_city", "contributor_state", "amount", "committee_name_x"]].head()
Explanation: Top contributions in opposition to the proposition
End of explanation
merged.groupby(["committee_name_x", "committee_position"]).amount.sum().reset_index().sort_values("amount", ascending=False)
Explanation: Total intake, by committee, for and against the proposition
End of explanation
top_contributors = merged.fillna({'contributor_firstname': 'NotAFirstName', 'contributor_lastname': 'NotALastName'})
top_contributors = top_contributors.groupby(["contributor_firstname", "contributor_lastname", "contributor_city", "committee_position"]).amount.sum().reset_index().sort_values("amount", ascending=False)
top_contributors.head(10)
Explanation: Top individual and organizational contributors for and against the proposition
Used fillna() to fill missing (NaN) values for contributors' first and last names
Combination of first name, last name, city and "position" assumed to be unique individual
End of explanation
<END_TASK>