BW #85: PACs and parties
You've probably heard that the US is holding elections on Tuesday, November 5th – not just for president, but also for a variety of other federal, state, and local positions. The US, more than many other countries, allows and encourages people to donate not only to their favorite politicians and their parties. There are limits on how much you can give to a candidate, but there are many fewer limits on how much you can donate to a political action committee (PAC). A PAC isn't allowed to coordinate with a candidate, and ostensibly represents people with a particular viewpoint that's distinct from a political party. But the line between party, candidate, and PAC is often quite blurry.
This doesn't mean that there's zero oversight of PACs and the money they raise. The Federal Elections Commission (FEC, https://en.wikipedia.org/wiki/Federal_Election_Commission or https://fec.gov) publishes information about candidate, party, and PAC fund-raising on a regular basis. In this way, we can know which PACs have raised more money than others -- even if we cannot technically know which candidates they are supporting.
This week, we'll look at the FEC's latest report of PAC and political-party spending, building a Pandas data frame containing information from their file. However, we won't be querying the data frame directly. Rather, we'll be building a dashboard -- a Web-based application -- that will allow us, as well as other people, to make queries against the PAC and party data.
To do this, we'll use Streamlit (https://streamlit.io/), an open-source project that makes it fairly easy to create data dashboards. I've heard about Streamlit for several years, and have heard only the best things about it, both from friends and from their representatives at PyCon. But it was only in the last week that I started to experiment with Streamlit in earnest, and I was so bowled over that I decided to incorporate it into this week's challenges.
If you're new to Streamlit, then I promise it's not that hard to learn, especially if you know some Python and Pandas. Understanding Web development helps, but is (surprisingly) far from crucial. You can start with the Streamlit tutorial:
https://docs.streamlit.io/develop/tutorials
I have relied quite a bit on the API documentation, too:
https://docs.streamlit.io/develop/api-reference
Here's a cheat sheet that I found useful, too:
https://cheat-sheet.streamlit.app/
Data and six questions
The FEC provides a great deal of data. You can query and visualize much of it on their Web site, but we want to download the data to our own system, so as to create a data frame from it and then write a Streamlit program to use it. The bulk-data download page is at
https://www.fec.gov/data/browse-data/?tab=bulk-data
On that page, scroll down to "PAC summary," and click on the +
sign to its right. That'll open up a number of links, each for a different two-year election season. Click on 2023-2024, or use this link:
https://www.fec.gov/files/bulk-downloads/2024/webk24.zip
That should download a zipfile for PAC data. When it is unzipped, it'll contain a single text file, webk24.txt
, with the PAC data.
A data dictionary, and a list of the column names and descriptions, is at
https://www.fec.gov/campaign-finance-data/pac-and-party-summary-file-description/
This week's learning goals include working with CSV data and building a data dashboard using Streamlit.
Here are my six tasks and questions; I'll be back tomorrow with my detailed solutions, including the Streamlit app that I created:
- From the data in
webk24.txt
, as well as the data dictionary for this data, create a data frame. The index should be the committee ID (CMTE_ID
), and the column names should be taken from the data dictionary. - Create a Streamlit app that displays this data frame, in its entirety. Have a title (e.g., "PAC fund-raising explorer") at the top of the page.