Each topic starts with a real scenario and a bar model, then three levels of exercises. Level 1 (Guided) fills in the blanks of a finished function. Level 2 (Practice) applies it to new numbers. Level 3 (Challenge) asks a new question with little scaffolding. The R and Python exercises run in your browser: click Run Code to try, Submit Answer to check, and use the hint or solution if you get stuck. Excel exercises have a solution you can reveal.
1 Book Topics
Tracking vs. budgeting: tracking records where money actually went; budgeting allocates where it should go; comparing the two creates a feedback loop
Capture methods: spending journal, checkbook register, cash envelopes, bank statements; pick one and run it for a full month
Categorizing: start with about 10 stable buckets (housing, transportation, groceries, dining out, subscriptions, personal, health, gifts, fun money, other); when in doubt use “Other”, and only promote a new category after seeing it three months in a row
Using spreadsheets: bank exports have Date, Description, and Amount columns; a keyword lookup adds the Category column in one pass
Monthly review: pull, categorize, compare to budget, and pick one change for next month
Online subscriptions: Americans spend about $219/month on subscriptions and underestimate it by $133; audit every quarter and cancel anything unused in 30 days
Math: the subscription audit, the opportunity cost of a $20/month subscription invested at 7% for 30 years (about $22,700)
2 Bank Statement Data
A minimal bank export has three columns: Date, Description, and Amount. The code blocks below show how to create an example bank statement file in R, Python, and Excel.
We can view the bank statement in R using knitr::kable().
3 Categorizing Transactions
A bank export only says where the money went (Description). Adding a Category column turns a list of merchants into budget buckets. In R, dplyr::case_when() checks each rule in order and the first match wins; in Python, numpy.select() does the same with a list of conditions and a list of labels; in Excel, IFS() does it one cell at a time. Anything that matches no rule falls into “Other”.
3.1 Level 1: Guided
Fill in the blanks so grocery stores (Trader Joe’s, Whole Foods, Costco) become “Groceries” and everything without a rule becomes “Other”. How many transactions are groceries?
With Description in column B, write an IFS() formula in D2 that labels subscriptions, groceries, and “Other”, then fill it down and count the groceries.
NoteSolution
SEARCH() finds a keyword in a cell, ISNUMBER() turns that into true/false, and OR() joins several keywords. The final TRUE, "Other" catches everything else.
Next month’s export has three new merchants: Safeway (groceries), Hulu (a subscription), and Uber (transportation). The rules below don’t know them yet, so they land in “Other”. Update the rules so no transaction is left in “Other”.
Real bank exports are messy: the same merchant can show up as NETFLIX.COM, Netflix, or netflix. The rule below only matches the exact capitalization, so it finds just 1 of the 3 subscriptions. Change the code so capitalization doesn’t matter, and count the subscriptions again.
Once every row has a category, the book’s three tracking questions take one short pipeline each: what did subscriptions cost, what share of income went to fixed costs, and which variable category was biggest? Spending is stored as negative numbers, so a minus sign turns a spending total positive.
Find the biggest variable category without scrolling through the rows.
NoteSolution
Select the data and use Insert → PivotTable with Category in Rows and Amount in Values, then sort smallest to largest (spending is negative). Or list the variable categories in F2:F4 (Groceries, Transportation, Dining), total each in G2 with =-SUMIF(D:D, F2, C:C), fill down, and use:
=INDEX(F2:F4, MATCH(MAX(G2:G4), G2:G4,0))
The answer is Groceries ($303.35).
Filter out the skip categories with ~statement["Category"].isin(skip), then groupby("Category")["Amount"].sum(). Spending is negative, so the biggest is .idxmin().
A $20/month subscription feels trivial. Cancel it and invest the $240 a year instead, and the chart below shows what that money grows into at each checkpoint, split into the money you put in and the growth it earned.
Formula: Annual cost × ((1 + r)^n − 1) ÷ r = Opportunity cost in n years
With the book’s 7% real return (the return after inflation), r = 0.07.
$240 a year invested at 7% instead of a $20/month subscription
$240 a year invested at 7% instead of a $20/month subscription
Each bar adds another year’s $240 to everything saved so far, and the whole pile grows by 7%. After 30 years you put in $7,200, and growth added about $15,500.
5.1 Level 1: Guided
Fill in the blanks to finish subscription_opportunity_cost(), then find what a $20/month subscription costs over 30 years at 7%.
Audit all four subscriptions from the bank statement (Netflix $15.99, Spotify $10.99, NYTimes $17.00, 24 Hour Fitness $39.99). What is their combined opportunity cost over 30 years?
The audit formula adds money once a year. Subscriptions are really paid monthly. Write monthly_opportunity_cost(monthly_cost, years, rate = 0.07) that invests every month (use a monthly rate and the number of months), then price the survey’s $219/month over 30 years.