Skip to content
/ pfn Public

Python For Nonprofits, currently a work in progress, will demonstrate how to use Python to retrieve, analyze, visualize, and share nonprofit data.

License

Notifications You must be signed in to change notification settings

kburchfiel/pfn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python for Nonprofits

By Kenneth Burchfiel

Released under the MIT License

Python for Nonprofits (PFN) is a guide to applying Python in nonprofit settings. Specifically, it teaches you how to use Python to:

  • Import data, then clean and reformat it
  • Analyze data using descriptive statistics and linear regressions
  • Create both charts and maps
  • Share spreadsheets and interactive visualizations online

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 (https://greenteapress.com/wp/think-python-3rd-edition/). (I found the 2nd edition of this book to be very helpful in my own studies.) However, as long as you have an introductory background in the language, you should be in a great position to benefit from this project.

Many Python for Nonprofits sections incorporate simulated data from a fictional university (Northern Virginia Catholic University, or NVCU for short). Educational institutions have a ton of data and many reporting needs, so it made sense to center much of the text on data analysis work for a university. However, PFN also makes use of real-world data from the US Census.

I've released PFN under the MIT license. This means that you can use this code in both commercial and personal applications, and that you can choose whatever license you want for your own code. You would just need to give me credit if you use a substantial amount of the code. This choice of license makes PFN much more flexible than many other educational Python resources.

For a more comprehensive guide to to Python for Nonprofits, reference its Introduction section.

Sample Output

Python for Nonprofits will teach you how to create visuals like the following:

(These are all static images, but you'll also learn how to create interactive HTML versions of these charts as well.)

Visualizations are just one component of Python for Nonprofits, but I did want to add some images to this Readme--and maps and charts make for more interesting images than do screenshots of tables!

How to Use This Resource

Python for Nonprofits is designed to be read from the start to the finish, much like a book. (Indeed, there is a PDF book version of this code available at this link. The book has been released under the MIT License, just like the rest of the project.) If you'd like to use PFN in this manner, you can choose from the following options:

  1. You can download and read through the PDF book that I linked to above.

  2. You can download the entire project, then open docs/index.html within the downloaded folder. This will launch an HTML-based version of the book that includes a built-in table of contents. (Note: I used Jupyter Book to create both the PDF- and HTML-based versions of the book.) I do plan to make this HTML-based book available online as well, but I'll first need to work out some bugs with the online version.

  3. You can go through the Jupyter Notebooks, Markdown documents, and Python files that comprise PFN one by one. (The suggested order for doing so is provided below.) If you choose this method, I would still encourage you to first download the project, as you'll then be able to run the files locally.

Note: When running these notebooks on your own computer, you may want to confirm that the render_for_pdf setting within the Appendix/helper_funcs.py file is set to False. That way, many visualizations will appear in interactive HTML rather than static PNG format. (If render_for_pdf was initially set to True, you'll need to rerun each section after changing it to False in order for that change to take effect.)

You can of course choose to skip over sections with which you are already familiar or don't (yet) have a need for; however, do keep in mind that later sections assume that you have already read through earlier ones.

Finally, the best way to internalize this content is to use it as the starting point for your own projects. In the future, I may also add suggested 'homework' that will make this practice a bit more formal--but for now, you'll need to 'BYOA' (bring your own assignments). One option would be to find a dataset related to a subject that interests you, then apply the contents of each section to clean, analyze, and visualize it.

Initial setup

I created much of PFN within Jupyter Desktop, an open-source tool for opening and viewing Jupyter Notebooks. I recommend that you use this program for viewing PFN notebooks also, though PFN should run well within other Jupyter Notebook viewers as well.

You'll of course also want to have Python set up on your computer. As noted within The Case for Python at Nonprofits, I recommend that you install and use Python (and the libraries that PFN applies) via Miniforge rather than Anaconda, as you may not be able to use the latter for free.

Although most of the libraries that Python for Nonprofits uses are available within conda-forge (https://github.com/conda-forge), some may need to be installed via pip (https://pypi.org/).

Table of Contents

[Note: this table of contents does not reference source data files, but the code files will help you locate them.]

README [this page]

Part 1: Introduction

  1. Introduction

  2. The Case for Using Python at Nonprofits

Part 2: Importing and Prepping Data

  1. Data Retrieval

  2. Data Prep

  1. Descriptive Stats

  2. Descriptive Stats: Part 2

  3. Census Data Imports

    1. Census Data Import Scripts

Part 4: Visualizing Data via Graphs and Maps

  1. Graphing

  2. Pivot and Graph Functions

  3. Choropleth Maps

    1. Plotly Choropleth Map Functions
  4. Choropleth maps with Folium

    1. Folium Choropleth Map Functions

Part 5: Regressions

  1. Regression Analyses

Part 6: Publishing Analyses Online (via Static Sites, Online Spreadsheets, and Dash Apps)

  1. Creating a Simple Static Webpage

  2. Updating Online Spreadsheets

    1. Weather Data Import

[The following two links will take you to Dash App project folders. These folders contain both a readme and additional Python/data files.]

  1. Simple App Without Login

  2. PFN Dash App Demo

Part 7: Appendix

  1. Helper Functions

  2. NVCU Database Generator

I had a great time putting Python for Nonprofits together, and I hope that you find that this work helps advance your own nonprofit career. Feel free to contact me at [email protected] (or post a message at https://github.com/kburchfiel/pfn/issues ) if you have any questions or notice any errors with the text.

Happy coding!

--Ken

About

Python For Nonprofits, currently a work in progress, will demonstrate how to use Python to retrieve, analyze, visualize, and share nonprofit data.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published