Data analysis with plain Python lesson plan
Do by hand what pandas does, on an ocean buoy's log: load and clean a CSV, describe it with statistics, group with Counter, chart in text, correlate, and turn a year of sea, waves, wind and rain into a report with a live rain gauge.
Objectives and materials
By the end, students can
- Read a CSV the right way, then clean what the buoy got wrong.
- A month of ocean in a few honest numbers, counted and grouped.
- Charts made of characters, and the math of two columns moving together.
- A year of ocean weather, from raw file to a report and a storm lamp.
Materials for the whole unit
- Half breadboard
- LED x 2
- Pushbutton
- Raspberry Pi 4 Model B
- Resistor x 2
Every part is already on the simulator’s bench, so there is nothing to buy or hand out. The counts are the most any one lesson uses, if you build it on real breadboards too.
Get the data in
Read a CSV the right way, then clean what the buoy got wrong.
| Lesson | Time | What students do |
|---|---|---|
| Loading dataRead a buoy log from a CSV tab: lines, then rows with the csv module, numbers with int() and float(), a crash and how to survive it, rows by column name with DictReader, and the first sign that the data is lying. | 55 min |
|
| CleaningFix what real data gets wrong: stray spaces and lowercase, blanks turned into None, range checks that catch sentinels, a repeated day thrown out, a clean file written, and the cleaner moved into its own module. | 55 min |
|
Materials
- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2
Check for understanding
Each student finishes "Cleaning" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "A module for the cleaner".
Describe it
A month of ocean in a few honest numbers, counted and grouped.
| Lesson | Time | What students do |
|---|---|---|
| statisticsDescribe a month of ocean in a few numbers with the statistics module: mean against median and why a storm splits them, standard deviation and the n-1 question, z-scores that find the unusual day, and a summary table. | 55 min |
|
| Grouping with CounterCount and group like a database does: collections.Counter and most_common, shares that print as percentages, binning waves into sea states, a mean per wind direction with setdefault, and a count per week. | 45 min |
|
Materials
- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2
Check for understanding
Each student finishes "Grouping with Counter" on their own, without opening the hints. The simulator checks 5 of its 5 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "Count per week".
See it and relate it
Charts made of characters, and the math of two columns moving together.
| Lesson | Time | What students do |
|---|---|---|
| Text chartsDraw data with nothing but print: a bar chart, bars scaled to a width, a histogram of wave heights, a time series turned on its side, and sparklines that fit a month on one line. | 45 min |
|
| CorrelationDo two columns move together? A text scatter plot, covariance, Pearson r built from its definition (this engine has no statistics.correlation), a negative correlation that is real oceanography, a one-day lag, and what one outlier does to r. | 55 min |
|
Materials
- Half breadboard
- LED x 2
- Raspberry Pi 4 Model B
- Resistor x 2
Check for understanding
Each student finishes "Correlation" on their own, without opening the hints. The simulator checks 6 of its 6 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "One storm, one r".
Project
A year of ocean weather, from raw file to a report and a storm lamp.
| Lesson | Time | What students do |
|---|---|---|
| Project: a year of ocean weatherThe whole course on a year of Buoy K7: load and clean 52 weeks, compare the seasons, chart the sea temperature, correlate wind, waves, sea and rain, find the records, and add a live rain gauge with a storm lamp on the Pi. | 60 min |
|
Materials
- Half breadboard
- LED
- Pushbutton
- Raspberry Pi 4 Model B
- Resistor
Check for understanding
Each student finishes "Project: a year of ocean weather" on their own, without opening the hints. The simulator checks 7 of its 7 steps as they go.
Then ask each one to explain, in a sentence or two, the last thing it asked of them: "The storm lamp".
Teach this unit as a class
Start a class from this course and its 7 lessons are assigned in one go, in order. Students join with a six-character code or printed login cards, and each one’s work comes back to you.
The class tools are free for 30 days for one class of up to 20 students, with no card. The lessons themselves are free either way.