Connecting two tables, one step at a time
Connect two tables without changing what a row means.
This notebook loads students.csv and enrolments.csv from a local data folder, or from the instructor's GitHub URL if they are not present. Those CSVs are not bundled here. Run the notebook with internet access or supply the course files in data/.
Start here: notebook introduction and setup
Lab 1: Connecting two tables, one step at a time
CS203 Data Science Fundamentals | Uses Week 1 lecture material
Duration: 2 hours | Submit: one executed notebook by 23:59
You do not need to write a full program today. Read each short code cell, predict what it will do, run it, inspect the output, and answer the question below it.
You will use two tables:
- students: one row is one student;
- enrolments: one row is one student registered in one course.
The central skill is simple: before connecting tables, say what one row means in each table.
Your route through the lab
| Part | Time | What you do |
|---|---|---|
| 1. Look | 0:00-0:25 | Run cells and identify rows, columns, and keys |
| 2. Predict | 0:25-0:40 | Decide what should happen when two tables connect |
| 3. Connect | 0:40-1:05 | Complete one short merge and check the row count |
| 4. Summarise | 1:05-1:30 | Complete one group summary and explain its denominator |
| 5. Challenge | 1:30-1:50 | Change one group variable and interpret carefully |
| 6. Explain | 1:50-2:00 | Peer check, final explanation, restart and run all |
There are 10 code cells. Six are fully provided. You complete four tiny code tasks by replacing one blank or one variable name.
Python · cell 3 — read here, run in your notebook
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt
RAW_BASE = "https://raw.githubusercontent.com/Sabokrou/Sabokrou.github.io/main/teaching/data-science-fundamentals/datasets"
def load_table(name):
local = Path("data") / name
if local.exists():
return pd.read_csv(local)
return pd.read_csv(f"{RAW_BASE}/{name}")
students = load_table("students.csv")
enrolments = load_table("enrolments.csv")
print("students:", students.shape)
print("enrolments:", enrolments.shape)Lecture-to-lab connections 6 sections
Look at the student table →
The lecture defines a row and an identifier. Here you check that students has one row per person and choose the matching table.
Week 1: rows and measurement, PDF pp. 30–39
Compare students and registrations →
The lecture distinguishes people from repeated observations. This table repeats student IDs because each row is a course registration.
Week 1: rows, keys and joins, PDF pp. 32–39, 42–53
Join and check the tables →
many_to_one is the lecture's key rule in code. Unique student keys on the right prevent registrations from multiplying.
Week 1: joins, PDF pp. 42–53; Week 3 inventory is a later connection
Explain pass rates by study mode →
The mean of complete 0/1 outcomes is a rate. The denominator is course registrations, linking directly to the later lecture on counts and rates.
Week 1 Lab 1 summary; Week 5 rates and unknown outcomes, PDF pp. 5–24
Compare programmes carefully →
Changing groupby changes the comparison, not its causal strength. Course mix and preparation can still differ between programmes.
Week 1: claim ladder, PDF pp. 22–29; Week 5 course mix, PDF pp. 38–51
Write a cautious final explanation →
The lecture's claim ladder becomes a written answer: report the comparison, explain its limits and identify a useful next check.
Week 1: framing, claims, evidence and reproducibility
Before submitting
Complete the four small TODOs and explanations, write the 120–160 word final note, keep outputs visible, then restart and run all. Follow the current course submission instructions; the notebook's printed 23:59 time does not identify a date.
Source: Lab_01_Rows_Joins_Missingness_Student(3).ipynb. The download is a study copy; the original upload is unchanged.