By Kenneth Burchfiel
Released under the MIT License
In this project, I will demonstrate how nonprofits can use Python to retrieve, analyze, visualize, and share their data. This project is still in its early stages, but I plan to add a number of sections to it as time allows.
Note: This project is not meant to replace an introductory Python course or textbook. If you're new to Python, I suggest getting started with a resource like Think Python, 3rd Edition. (I found the 2nd edition of this book to be very helpful in my own studies.) Once you've finished reading Think Python or have a similar introductory background in the language, you should be in a great position to benefit from this project.
Note: many of these sections have not yet been completed or even started; in addition, other sections may be added in later on. I'm working on this project in my free time (which, as a new dad, is not very abundant!), so it may be a while before I begin or finalize a given section.
Part 1: Introduction
The Case for Using Python at Nonprofits explains why you should consider using Python at your nonprofit organization.
data_retrieval.ipynb (initial draft complete) provides a brief overview of importing data into Python scripts from multiple sources.
data_prep.ipynb (initial draft complete) shows how to clean and reformat data so that it can be incorporated into various analyses.
census_data_imports.ipynb (mostly complete) shows how to use Python to retrieve data from the US Census API, a great source of public-domain demographic data.
In descriptive_stats.ipynb (mostly complete), you'll learn how to use Python to calculate a range of descriptive statistics.
This section will show how to create linear regressions within Python.
Graphing (Work in progress)
graphing.ipynb currently shows how to use the Plotly library to create static and interactive bar charts. I plan to expand this script to demonstrate how to create line charts, scatter plots, and tree maps within Plotly as well.
pivot_and_graph_functions.ipnyb defines 'autopivot' and 'autobar' functions that can greatly reduce the amount of code needed to convert DataFrames into Plotly graphs. These functions will also get applied within the Online Visualizations section of PFN--though I haven't integrated them into that section just yet.
choropleth_maps.ipynb (initial draft complete) demonstrates how to use Folium to create interactive choropleth maps. Here are examples of the choropleth maps created within this section:
And here are static copies of these maps:
mapping_census_data.ipynb (mostly complete) shows how to create maps of the data retrieved via census_data_imports.ipynb.
This section will demonstrate how to use Python to export data to a Google Sheets workbook, thus enabling others to view that data.
Online Visualizations (Work in progress)
In this section, you'll learn how to use the Dash and Plotly libraries to create interactive online dashboards. The PFN_Dash_App_Demo subfolder contains the source code for the main Dash app created within this section; that app is hosted online here. This Dash project provides examples of both simple and more complex dashboards, including ones that make use of the powerful dash-pivottable package.
For a more barebones template that incorporates Flask-Login and Dash pages functionality (and nothing else), visit the Simple_App_With_Login section; its corresponding Dash app can be found here.
Part 6: Appendix
I used nvcu_db_gen.ipynb to construct a SQLite database with fictional data for an imaginary university. The tables in this dataset will play a role in many parts of Python for Nonprofits.