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.
Same patterns as today’s lab, on a different dataset. Enrolled in our Runestone course? Open it from there so your progress counts.
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.
| Part | What you do |
|---|---|
| 1. Load it | Use the 5.3 starter block. Print the row count and the first three rows. Write the count down. |
| 2. Three questions | Count: which club has the most members? · Average: what’s the average commute? · Max/min: longest and shortest commute? |
| 3. The number that looks wrong | One answer from Part 2 should look off. Investigate it. Recompute without the suspicious rows. Report both numbers. |
| 4. Your own question | Ask something no one told you to ask. Code it, answer it, and write one sentence on whether it surprised you. |
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
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.
| Criteria | Pts |
|---|---|
| File loads; row count reported correctly | 2 |
| All three questions answered correctly, each with its English question as a comment | 3 |
| Part 3: identifies the impossible value and reports both averages | 3 |
| Part 4: own question is answerable from the data, and it is answered | 2 |
| Total | 10 |
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.
count_where(rows, field, value) and call it for three different clubs. (That’s Mini-Project 4’s requirement, arriving early.)