Unit 5 · Data · Lesson 5.4

Asking a Dataset a Question

Three thousand rows tell you nothing by staring. You need a question first — in English, at the top of your file, before any code. Then the tools are ones you already own: traverse, count, accumulate.

Big Idea 2 — DataCED 2.3, 2.4 · Fluency day — no new vocab

Before this lesson — read on Runestone

Notice each section starts with a question, then writes the loop that answers it. Enrolled in our Runestone course? Open it from there so your progress counts.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

Big Data, powered by Programs. The file is loaded (5.3). Today the Unit 3 toolkit — traverse, count, accumulate, compare — turns rows into answers. Nothing new; that’s the point.

2

The Hook

Here are 3,000 rows. What do you see? Nothing. A wall of commas. A dataset doesn’t say anything until someone asks it something specific.

So: what do you actually want to know? And — the question that matters more — does this data contain what you’d need to answer it?

3

The Idea

Every data question in this unit runs the same three steps:

  1. Question — written in English, as a comment, before any code.
  2. Check the columns — name the fields the question needs. If one doesn’t exist, the question dies here.
  3. Answer — with one of four patterns you already know from Lab 3.10: count, sum, average, max/min.

Python

# Q: How many members commute
#    more than 20 minutes?
count = 0
for row in rows:
    if int(row["commute_min"]) > 20:
        count = count + 1
print(count)

AP Pseudocode

// commutes: a list of minutes
 
count ← 0
FOR EACH c IN commutes
{ IF (c > 20)
  { count ← count + 1 } }
DISPLAY(count)

Hover or tap a line to light its twin. This is the accumulator from 3.4. The only difference is where the list came from. Python pulls a field out of each row; the AP version starts with the list already made — which is how every exam question gives it to you.

The fourth question matters most. For any dataset, write three questions it can answer and one it can’t. Knowing what a dataset can’t tell you is the skill the exam rewards most in this unit — and the one most students skip.
4

Try It — Can This Data Answer It?

The club-signups dataset has these fields: student_id, name, grade, club, city, commute_min, club_hours_per_week, screen_time_hours, signup_date. For each question: A = answerable from these columns, N = not answerable.

In class

Write three questions the club dataset can answer and one it can’t. For the one it can’t, name the missing column. Then answer one of your three with a loop — question as a comment on top.

5

Vocabulary

No new terms today — on purpose. This is a fluency day: the words you need are record, field, traverse, and accumulator, and you already own all four.

6

Check

Five questions. Trace the pseudocode on paper — this is exactly the exam’s item shape.

0 of 5 answered
7

Impact Check

Say exactly what was measured

A dataset of complaints measures complaints. A dataset of app downloads measures downloads. The gap between “what was counted” and “what we wish we knew” is where most bad headlines live.

8

Connections

Came from 3.4 + 3.10 — the accumulator and the four canonical algorithms. Same code, real rows.
Next in Lab 5.5 — three questions, answered on the full club dataset, each with its English question on top.
Returns in 5.9 — the questions data can’t answer — especially “why” — get a full lesson.
Returns on the exam — “What does this program display?” with a loop and an IF over a list. You just did five.
← 5.3 Reading a CSV