Good place to stop if you're short on time — step 3 picks up here.
Lesson idea Tap to fold
What is a list of dictionaries good at representing?
Show the answer
Several records that share the same named fields.
A named table, not a special print layout
pandas is a Python library for tabular data. import pandas as pd gives the module a short local name. DataFrame builds a two-dimensional table from row dictionaries. A Series is one named column; tolist converts its values into an ordinary list.
len(df) counts rows; df.shape returns (rows, columns); df.columns holds column labels. An empty table needs explicit columns if later code selects them. Do not grade the decorative printed table layout. The first Run loads pandas in the browser and needs internet; no computer installation is required for this Lab.
This course’s pinned browser runtime supplies pandas 2.2.3 and NumPy 2.0.2. A different local library version may display data differently; the checks use values and behavior.
# A named table, not a special print layout.
import pandas as pd
rows = [
{"model": "Museum", "score": 5},
{"model": "Canal", "score": 3},
]
df = pd.DataFrame(rows)
print(df.shape)
print(df["score"].tolist())
empty = pd.DataFrame(columns=["model", "score"])
print(empty.shape)
(2, 2), then [5, 3], then (0, 2). Columns still exist in the explicit empty table.
Know whether you have a table, one column or a Python list. Next, select rows with one boolean per row.
Predict, explain, then test
These three brief checks are self-reviewed, not scored. Answer before opening the comparison. Coding checks use unfamiliar tables under the stated task assumptions.
Name a shape
What does shape (0, 2) describe?
Compare your answer · self-reviewed
Zero rows and two named columns, not two rows or an unusable schema.
Choose a representation
What does df["score"].tolist() return?
Compare your answer · self-reviewed
An ordinary list containing the ordered values from the score Series.
Explain an error
Does DataFrame([]) automatically have a score column?
Compare your answer · self-reviewed
No. Supply columns for an empty table before selecting a required column.
Choose an exercise to load its prompt.
Loading exercises…
Noted on your route map, with the step you were on. Nothing is lost by parking it — the next review day will bring this idea back, and the flag tells the course where to slow down.
The tutor mounts here when JavaScript is available. The lesson above stays readable without it.