Lectures 8–9: parameters, lookups, distributions; Copilot drafts, you verify
Python: the same algorithms, written once, run many times
flowchart TB
subgraph excel [Excel]
T1[Tidy table]
F1[Formulas / pivot]
C1[Hand-checked row]
end
subgraph py [Python]
T2[Read table]
F2[Code the same rules]
C2[Print or write summary]
end
C1 --> M[Do they match?]
C2 --> M
Excel thinking, Python words
A translation table
Excel
Python (idea)
Cell B2
A variable, or row["score"]
Number vs Text vs Date
int / float vs str vs date types
=C2/$B$1
score / points_possible
=IF(A2>=70,"OK","Review")
status = "OK" if total >= 0.7 else "Review"
Fill down
A for loop, or a vectorized column operation
PivotTable SUM by category
groupby("category")["attendance"].sum()
MEDIAN / AVERAGE
median(...) / mean(...) on a list or column
Workbook .xlsx
A file you read and write
Types did not go away
"10" + "20" in Python is "1020" (text)
10 + 20 is 30
Same trap as Excel numbers stored as text
Dates still need to be dates if you want to sort or subtract them
Microsoft 365: Python in Excel (if available)
Some Office 365 Excel builds can run Python in a cell (=PY(...))
That is still “Excel as the interface, Python as the engine”
We may also use a simple notebook or .py file; the thinking is the same
Placeholder: confirm lab software (Anaconda, VS Code, Excel Python) on D2L
A first automation
Minimal story
You already have a correct Excel Table and a weighted total
Export or save the data (CSV or .xlsx)
Python reads the rows
Python applies the same weights
Python prints who is Review
You compare to the Excel Status column
Placeholder code (shape, not a finished lab)
1
2
3
4
5
6
7
8
9
# weights match the Excel parameter cells
W_QUIZ,W_PROJECT,W_EXAM=0.3,0.3,0.4# one student, same numbers as a checked Excel row
quiz,project,exam=0.80,0.70,0.60weighted=quiz*W_QUIZ+project*W_PROJECT+exam*W_EXAMstatus="Review"ifweighted<0.7else"OK"print(weighted,status)
If this printout disagrees with Excel, fix the definitions before writing more code
Next step in the real project: loop over a file instead of one student
From one row to a file
Read CSV with the standard library or pandas (to be chosen in the assignment)
Skip the same junk you cleaned in lecture 2 (extra headers, total rows)
Write a small summary: category totals you already pivoted in lecture 7
Goal: same question, same answer, less clicking
Checking Excel against Python
Correctness is a comparison
Pick 3 rows: typical, boundary, messy (blank or text number)
Record Excel values in a Checks sheet
Print Python values for the same IDs
Differences are bugs (type, rounding, filter, off-by-one), not “Python being different”
Rounding
Excel and Python may show 0.699999 vs 0.70
Decide a rule (round to 2 decimals before the IF) and apply it in both places
This is still SLO4: appropriate data types and formulas
Copilot, again
Allowed: “Write a loop that computes the same weighted total as =... in Excel”
Required: you paste the Excel formula into the prompt and then run the checks above
Not allowed: a script you cannot walk through in office hours
Try this
Lab — Match one known row (Python Project 1 warmup)
In Excel, freeze a checked student: scores, weights, weighted total, status
Type those same numbers into the small Python snippet (or Excel =PY cell)
Confirm printed weighted and status match
Change one score in both places; confirm both update the same way
Lab — Automate a pivot (Python Project 2 preview)
Excel: Pivot SUM of attendance by category (lecture 7)
Python: group the same columns and print the sums
Optional: median attendance by category vs Excel MEDIAN in a value field
Paste both summaries into Word with one sentence: do they match? if not, why?
Discussion
Designate a note-taker
Which of your Excel projects would be painful to repeat next semester, and what would a script need as input?
If Python and Excel disagree, list three checks before you blame the language
Takeaways
End of the opening arc
Computers store typed values and follow instructions (lecture 1)
Data literacy comes before features (lecture 2)
Excel is where you write and see those instructions (lectures 3–8)
Distributions and Copilot still require a check (lecture 9)
Python repeats a verified analysis (this lecture)
Placeholder notes for expansion
Exact toolchain (Excel Python vs Jupyter vs .py in VS Code)
Starter CSV matching Excel Project data
Project 1: reproduce a SUMIF / pivot
Project 2: batch two workbooks and write a combined summary
Excel Exam 2: independent workbook covering the semester, no Copilot