Tools to aid with data analytics at PHA.
Pick one of the two install methods below. If you are only going to use the tools in a notebook, do the first. If you are going to contribute to the code, do the second.
Make sure your desired Python environment is active, then type:
pip install "pha_tools @ git+https://github.com/DillerDigital/PHA"
- Install git on your machine.
gitis a tool for synchronizing source code with someone else. - Make sure your desired Python environment is active, then type:
$ git clone git@github.com:DillerDigital/PHA.git
$ cd PHA
$ pip install -e ./
To update pha_tools to the latest version, use this command:
pip install --upgrade "pha_tools @ git+https://github.com/DillerDigital/PHA"
In a script or in a Jupyter Notebook:
from importlib.resources import files
from pha_tools.io import (
gather_data_filenames, load_donation_data_from_filenames
)
from pha_tools.reports import donations_by_donor, donations_by_year
# Modify data_dir below to point to the directory with your data files.
# `files("pha_tools")1 points to the sample files included with `pha_tools`
data_dir = files("pha_tools") / "data"
print(data_dir)
glob_text = 'transactions*.xlsx'
filenames = gather_data_filenames(data_dir, glob_text)
donations = load_donation_data_from_filenames(filenames)
year_report = donations_by_year(donations)
print(year_report)
year_report.to_excel("Yearly_Donations_Report.xlsx")
donor_stats = donations_by_donor(donations, report_year=2025)
print(donor_stats.head(50))
donor_stats.to_excel(f"Donor_Stats_{2025}.xlsx")This uses data from sample notebooks to generate a yearly report, showing year-to-year changes in number and kinds of donors and donations, and a donor report, showing summary history for each donor.
To adapt the code to your own data, locate the folder with the transactions data you want to load in Windows Explorer. Right-click and copy the path to that folder and substitute it for the expression after data_dir = in the code above.