Unit 5 · Data · Lesson 5.5 · Lab

Lab: First Data Dive

Your first real dataset: 181 club signups. Load it, answer three questions with the four canonical algorithms, find the number that looks wrong, and ask one question of your own.

Big Idea 2 — DataCED 2.3, 2.4 · Lab 5.5 · 10 pts

Before this lesson — read on Runestone

Same patterns as today’s lab, on a different dataset. 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. End of Week 1: what data is (5.1), what describes it (5.2), how to load it (5.3), how to ask it something (5.4). Today all four at once, on real rows.

2

The Brief

181 rows. Three questions. One of the answers is wrong. Not wrong because of your code — wrong because of the data. Finding it is Part 3, and it’s the most important thing you’ll do today.
PartWhat you do
1. Load itUse the 5.3 starter block. Print the row count and the first three rows. Write the count down.
2. Three questionsCount: which club has the most members? · Average: what’s the average commute? · Max/min: longest and shortest commute?
3. The number that looks wrongOne answer from Part 2 should look off. Investigate it. Recompute without the suspicious rows. Report both numbers.
4. Your own questionAsk something no one told you to ask. Code it, answer it, and write one sentence on whether it surprised you.
3

The Model

Here are all four patterns on a different dataset — 12 bike-share trips. Your lab is the same shape on the club data. Note the English question above each block.

import csv
with open("trips.csv", newline="", encoding="utf-8") as f:
    rows = list(csv.DictReader(f))

# Q1 (count): How many trips started at the Park station?
park = 0
for row in rows:
    if row["station"] == "Park":
        park = park + 1

# Q2 (average): What is the average trip length in minutes?
total = 0
for row in rows:
    total = total + int(row["minutes"])     # int() — it's a string!
avg = total / len(rows)

# Q3 (max/min): What are the longest and shortest trips?
lengths = [int(row["minutes"]) for row in rows]
print(max(lengths), min(lengths))           # earned in Unit 3
“Which club has the most members?” needs one count per club. Start with a count for one club; once that works, 5.7 shows the tidy way to count every club at once. A version that counts each club with a separate loop is fully acceptable today.
4

Try It — Check Your Loop

Before running on 181 rows, prove your patterns on 12. Here’s the whole trips dataset. Compute each answer by hand or in Python, type it, and check.

5

What You Turn In

CriteriaPts
File loads; row count reported correctly2
All three questions answered correctly, each with its English question as a comment3
Part 3: identifies the impossible value and reports both averages3
Part 4: own question is answerable from the data, and it is answered2
Total10
6

How to Work

Four rules for today

1. CSV in the same folder as your .py file. Most of today’s problems are this one.

2. Let it crash. If averaging a column throws an error, read the error: it’s telling you about the data. Write down which value broke it. That’s tomorrow’s lesson.

3. Question first. English comment, then code. Every time. It’s graded.

4. Suspicious? Look at the rows. Print the rows behind a strange answer before you trust it — or before you “fix” it.

A tie is an answer. If two categories have the same count, say so. Reporting only one, without noticing the other, is a data mistake — not a code mistake.
7

Challenge Tier

8

Connections

Came from Lab 3.10 — count, sum, average, max/min — same four algorithms, real rows.
Next in 5.6 — the values that crashed your code or skewed your average get a name, and a rule.
Returns in Lab 5.8 — the same dataset, cleaned, grouped, and charted.
Returns on the exam — “Which value would distort this result?” That’s Part 3.
← 5.4 Asking a Dataset a Question