Logan's Analytics Bootcamp
Dashboard β€Ί Phase 4: Python for Report Automation
M4.1

Python Foundations for Analysts

⏱ 8 hoursπŸ“… Weeks 19–20❓ 4 quiz questions
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 optionally docxtpl). Work only with the fictional dataset while learning.

🎯 Learning objectives

Tick each one when you can actually do it.

πŸ’‘ Key concepts

  • Setup: python -m venv .venv β†’ activate β†’ pip install pandas openpyxl python-docx matplotlib. Keep a requirements.txt.
  • Tools: VS Code with the Python extension. Jupyter notebooks for exploration, .py scripts for repeatable automation.
  • Core syntax mapped to Excel thinking:
    Excel idea Python
    Cell value variable cpi = 0.93
    Range / column list [0.93, 1.02, 0.88]
    Lookup table dict {"PRG-001": "KESTREL", ...}
    IF / IFS if / elif / else
    Fill down a formula for loop or list comprehension
    LAMBDA def function
  • f-strings: f"{program}: CPI {cpi:.2f}, CV ${cv:,.0f}"
  • pathlib for file paths: Path("Data") / "milestones.csv"
  • Errors: read tracebacks bottom-up. try/except for expected failures (missing file).

πŸ›  Hands-on exercise: EVM Functions in Python

⬇ Practice data for this module
D1 programsProgram dimension (12 rows)CSVXLSX
D2 milestonesMilestones (~150 rows)CSVXLSX

Data: a hard-coded list of dicts for 5 programs: {"program": "PRG-001", "bcwp": 4_200_000, "acwp": 4_650_000, "bcws": 4_500_000, "bac": 18_000_000}.

  1. Write functions cpi(ev, ac), spi(ev, pv), eac_cpi(bac, ev, ac), rag(idx) that handle divide-by-zero (return None).
  2. Loop over programs and print a formatted line per program.
  3. Write the results to a CSV with the csv module.
  4. Wrap the file write in try/except and print a helpful message if the folder doesn't exist.

πŸ“¦ Mini-project: Milestone Countdown Script

A script that reads milestones.csv with the csv module (no pandas yet), finds incomplete milestones forecast within the next 60 days, sorts them by date, and prints a clean text report grouped by program, with days remaining and slip vs. baseline.

🧠 Self-check quiz

Answer in your own words, then check. Grade yourself honestly; your score is saved.

Q4.1.1
Why use a virtual environment?
Write at least a few words to unlock.
Q4.1.2
What Python structure is most like an Excel lookup table?
Write at least a few words to unlock.
Q4.1.3
What does f"{x:,.0f}" produce for x = 1234567.89?
Write at least a few words to unlock.
Q4.1.4
How should you read a Python traceback?
Write at least a few words to unlock.