Day 12 - Extracting columns
Skills: None
Pre-reading: 5.1.1 (PROBLEM: Google Sheets), 5.1.2, 5.1.3, 5.1.4.1
Intro (15 min)
...
FIXME
Basic Statistical Questions, Extracting Columns, and Understanding Lists
Focus: Introduce basic statistical queries over tables, show how to extract a column from a table, and explain what lists are and how to create them.
1. Introduction & Motivation (10 minutes)
- Context:
Imagine you run a small café that tracks daily sales in a table. Each day’s entry includes the number of coffees sold. - Discussion Prompt (Do Now):
- “What basic statistics might you want to know about your daily coffee sales? (e.g., maximum, average, total)”
- Have students share ideas.
2. Basic Statistical Questions on a Table (15 minutes)
- New Example Table:
We define a simple table of daily coffee sales.coffee-sales =
table: day, coffees-sold
row: "Mon", 45
row: "Tue", 30
row: "Wed", 55
row: "Thu", 40
row: "Fri", 60
end - Statistical Questions:
- Largest number sold on a day (maximum)
- Average coffees sold per day (mean)
- Total coffees sold (sum)
- Interactive Coding:
- Ask students: “How would you compute the average number of coffees sold?”
- Introduce Pyret’s math/statistics libraries:
import math as M
import statistics as S
sales = coffee-sales.get-column("coffees-sold")
M.max(sales) // maximum sales
S.mean(sales) // average sales
M.sum(sales) // total coffees sold - NEED TO DISCUSS
import
, module names, etc.
- Discussion:
- Which statistic might best help you plan staffing on a busy day?
3. Extracting a Column & Transition to Lists (15 minutes)
- Extracting the Column:
- Use the function
get-column
:coffee-sales.get-column("coffees-sold")
- Show that the result is printed as:
[list: 45, 30, 55, 40, 60]
- Use the function
- Discussion:
- How does a list differ from a table? (Lists have order but no column header, and only single value per entry.)
- Creating Literal Lists:
- Explain that lists can be defined directly:
sample-list = [list: 10, 20, 30]
empty-list = [list: ] - Do Now:
- Ask: “How would you create a list of weekdays? (Answer:
[list: "Mon", "Tue", "Wed", "Thu", "Fri"]
)”
- Ask: “How would you create a list of weekdays? (Answer:
- Explain that lists can be defined directly:
4. Wrap-Up & Reflection (10 minutes)
- Recap Key Points:
- How to ask basic statistical questions on a table.
- How to extract a column to obtain a list.
- The notion that a list is an ordered, anonymous collection of values.