Recitation 3 — Working with Tables
Skills: 2
Reading: 4.1
Define a Table Constant
Have students define a table containing information about several national parks:
PARKS = table: name, state, established, area-sq-miles, visitors-2024
row: "Yellowstone", "Wyoming", 1872, 3472, 4500000
row: "Yosemite", "California", 1890, 1168, 3900000
row: "Grand Canyon", "Arizona", 1919, 1904, 6400000
row: "Zion", "Utah", 1919, 229, 4700000
row: "Rocky Mountain", "Colorado", 1915, 415, 4300000
row: "Acadia", "Maine", 1916, 198, 2500000
row: "Great Smoky Mountains", "Tennessee", 1934, 816, 12100000
row: "Bryce Canyon", "Utah", 1928, 56, 2900000
end
Understanding Table Structure
Point out that tables have:
- Columns (name, state, established, area-sq-miles, visitors-2024)
- Rows (each park is one row)
- Headers that describe what each column contains
Accessing Individual Values
gActivity:** Show students vhow to extract specific data using row and column access:
# Get the name of the first park
PARKS.row-n(0)["name"]
# Get the number of visitors to Yosemite (row 1)
PARKS.row-n(1)["visitors-2024"]
Answering Questions with Data
Question 1: "Which park was established first?"
- Students should examine the 'established' column.
Question 2: "What's the total area of parks in Utah?"
- Students need to identify Utah parks and add their areas.
Filtering Tables
Explanation: Introduce the filter-with
operation to find rows that meet certain criteria.
Have students write filters to answer specific questions:
- Parks established before 1920.
- Parks with more than 4 million visitors.
Ordering and Sorting Tables
# Sort parks by area (smallest to largest)
parks-by-area = order-by(PARKS, "area-sq-miles", true)
As an exercise, now sort by number of visitors.
Check Understanding:
"What does the true
parameter mean in order-by?"
Wrap-Up
- "Which operation was most useful for answering questions about the data?"
- "What happens if you filter a table and get zero results?"