π₯οΈ Week 04 Lecture
From Loops to Vectorisation: NumPy and Pandas
π Logistics
Time and Location: Thursday, 23 October 2025, 16:00 - 18:00, CLM 5.02
Youβve just submitted the π Week 04 Practice, your first complete data science workflow using pure Python. Todayβs lecture revisits the loops you had to write for that exercise. Then weβll see how to scale that same logic to larger problems using numpy and pandas.
Note: Todayβs lecture covered Sections 1-6 of the demonstration notebook (loading data, loops, NumPy vectorisation, Pandas DataFrames, and filtering). Sections 7-8 (custom functions and .apply()) will be introduced in Week 05.
π Preparation
- Submit the π W04 Practice by today at 12:00 (noon)
- Review your loop logic for detecting hot days and counting streaks
- Reflect on where you used
forloops andif/elsestatements - Individual feedback on your submission will arrive within a week
π£οΈ Lecture Overview
Part 1: W04 Practice Solution (40 min)
- Walkthrough of the heatwave detection problem
- Dynamic state management in loops: building lists, accumulating counts, tracking streaks
- Scaling question: larger datasets or more complex conditions?
Part 2: Vectorisation with NumPy and Pandas (45 min)
- NumPy arrays for simple numerical operations
- Nested
np.where()for complex conditions (ugly!) - Pandas DataFrames with custom functions (cleaner)
- Comparing all three approaches
Part 3: Choosing Tools & Lab Preview (15 min)
- Decision framework: loops, NumPy, or Pandas?
- Tomorrowβs pair programming lab
- Mini-Project 1 (released tomorrow)
π Lecture Materials
Todayβs lecture uses Jupyter Notebooks instead of slides. All materials will be available in your Nuvolos workspace under the week04/ folder, or you can download them directly below.
Lecture Demonstration Notebook
This notebook walks through your W04 Practice solution and introduces NumPy/Pandas vectorisation. It includes Personal Reflection cells where you can take notes during the lecture.
Data Files
The lecture uses your W04 Practice data:
π‘ Key Concepts
- State management in loops: Building lists, counters, and tracking variables
- Vectorisation: Operations on entire arrays at once
- Tool selection: Loops, NumPy, or Pandas depending on the problem
π Appendix
PostβLecture Actions
- Review the lecture notebook and your personal notes
- Skim the π» W04 Lab instructions (pair programming!)
- Start exploring βοΈ Mini-Project 1 (released today or tomorrow)
- Post questions in
#helpon Slack
Useful Links
- π W04 Practice
- βοΈ Mini-Project 1 (due Week 06)
- π» W04 Lab (tomorrow)
Open-Meteo API
Using Nuvolos- π Syllabus
Looking Ahead
- Tomorrow: Pair programming lab (Pilot + Copilot roles)
- Mini-Project 1: Released today, due Week 06 Thursday 8pm (20% of grade)
- Next week (W05): Advanced data transformations and seaborn visualisation
- Week 06: Reading Week β focus time for Mini-Project 1
