Project: expense report from a messy CSV
From: Grace Mensah, Finance Operations
"Can you send me March expenses by team before Friday? The export is expenses_march.csv. Fair warning: people edit it by hand. Some amounts have dollar signs and commas, a few are blank, one claim was entered twice, and the dates are in two formats. A stray April claim may be in there too.
What I need: a summary.csv with one row per team (team, total, number of claims), biggest total first, totals with two decimals. Tell me how many rows you dropped and why."
Done looks like: summary.csv written, with duplicates, blank amounts and other months left out.
This project runs from a raw export to a file you could email. Each step builds on the one before, and your notebook keeps its variables from step to step, just like a real analysis. If you jump in at a later step, the earlier steps' code is already run for you.
The skills all come from earlier lessons: reading CSV with csv.DictReader, cleaning text amounts, parsing dates with datetime.strptime, grouping with a dictionary, sorting with a key, and writing CSV.
Check your counts as you go. Data cleaning goes wrong quietly: a duplicate that slips through or a date read the wrong way doesn't raise an error, it just changes the totals.
from datetime import datetime
def parse_date(text):
for fmt in ("%Y-%m-%d", "%m/%d/%Y"):
try:
return datetime.strptime(text, fmt).date()
except ValueError:
pass
parse_date("03/05/2026"), parse_date("2026-03-05")
Out: (datetime.date(2026, 3, 5), datetime.date(2026, 3, 5)). Try each known format until one fits.