Automating the End-to-End Report Pipeline
Phase 4 goal
Write Python that reads messy program data, transforms it with pandas, and generates finished Excel and Word deliverables (the same kind of document automation your coworker builds), reliably and repeatably.
Environment note: Use your organization's approved Python distribution if one exists. Some environments require specific installers, package mirrors, or a pre-approved package list. Packages used:
pandas,openpyxl,python-docx,matplotlib(and optionallydocxtpl). Work only with the fictional dataset while learning.
π― Learning objectives
Tick each one when you can actually do it.
π‘ Key concepts
- Project layout:
status_reporter/ βββ config.toml # paths, thresholds, reporting period βββ requirements.txt βββ run_reports.py # entry point (argparse: --period 2026-09 --program PRG-002) βββ reporter/ β βββ load.py # read + clean (Module 4.2) β βββ evm.py # calculations (Module 4.3) β βββ charts.py # matplotlib figures β βββ excel_out.py # openpyxl (Module 4.4) β βββ word_out.py # python-docx (Module 4.5) βββ templates/ βββ output/2026-09/ - Config, not hard-coding:
tomllib(standard library in Python 3.11+) to readconfig.toml. - Logging:
loggingmodule writing tooutput/run.log(what ran, row counts, warnings). - Validation gates: Stop or warn when totals don't reconcile (e.g., sum of program BAC vs. portfolio BAC), reporting periods are missing, or there are orphaned keys. A report that's wrong but looks polished is worse than no report.
- Reading from the same source as Power BI: Point Python at the same SharePoint-synced folder (OneDrive sync) or the cleaned CSV, so all outputs share one source of truth.
- Running it: Manually, Windows Task Scheduler, or Power Automate Desktop (if licensed and approved) calling a script. Write outputs to a OneDrive-synced SharePoint folder β a cloud flow (When a file is created in a folder) notifies reviewers or starts an approval.
- Reading your coworker's code: Look for the entry point (
if __name__ == "__main__":), follow the imports, and find where data is read, transformed, and written. Use these skills to maintain and extend shared scripts.
π Hands-on exercise: Refactor into a Package
Take your scripts from 4.2β4.5 and reorganize them into the layout above. Add argparse options --period and --program (default: all), logging, and a config file with thresholds (CPI amber/red, slip days).
π¦ Mini-project: Portfolio Report Run
One command (python run_reports.py --period 2026-09) produces:
- 12 program status reports (
.docx) with charts and tables - 1 portfolio roll-up Excel workbook (Summary, EVM, Budget, Milestones, Risks) with formatting and tables
- 1 portfolio executive summary (
.docx) listing programs with red CPI/SPI, slips > 30 days, and top risks - A
run.logand avalidation_report.csvRuntime target: under 1 minute. Then set up a Power Automate flow that emails you whenPortfolio_Summary_2026-09.docxappears in the SharePoint output folder.
π§ Self-check quiz
Answer in your own words, then check. Grade yourself honestly; your score is saved.
if __name__ == "__main__": do?