Lesson plan

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.

4 chapters, 7 lessons, about 6 hours, on the Raspberry Pi 4 Model B. Every lesson runs in the browser, with nothing to install.

The unit

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.

Chapter 1. About 1 h 50 min

Get the data in

Read a CSV the right way, then clean what the buoy got wrong.

LessonTimeWhat 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
  1. Meet Buoy K7
  2. Rows with the csv module
  3. Turn text into numbers
  4. Survive a bad row
  5. Rows by name with DictReader
  6. The data lies
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
  1. Tidy the text
  2. Blanks become None
  3. Range checks catch sentinels
  4. Throw out the repeat
  5. Write a clean file
  6. A module for the cleaner

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".

Chapter 2. About 1 h 40 min

Describe it

A month of ocean in a few honest numbers, counted and grouped.

LessonTimeWhat 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
  1. The mean, skipping gaps
  2. Mean or median?
  3. Take the storm out
  4. How spread out?
  5. z-scores find the unusual day
  6. A summary table
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
  1. Count with Counter
  2. Shares, and the missing key
  3. Bin numbers into kinds
  4. Group, then summarize
  5. Count per week

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".

Chapter 3. About 1 h 40 min

See it and relate it

Charts made of characters, and the math of two columns moving together.

LessonTimeWhat 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
  1. A bar chart from a string
  2. Scale the bars
  3. A histogram
  4. A time series on its side
  5. Sparklines
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
  1. A scatter plot in text
  2. Covariance
  3. Pearson's r, from scratch
  4. The wrong question
  5. Look a day later
  6. One storm, one r

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".

Chapter 4. About 1 h

Project

A year of ocean weather, from raw file to a report and a storm lamp.

LessonTimeWhat 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
  1. Load the year
  2. Four seasons
  3. Chart the year
  4. What moves together
  5. Records
  6. A live rain gauge
  7. The storm lamp

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".

Your class

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.