Before the questions, make sure you can: describe any dataset in Munzner's vocabulary (items, attributes, keys, values, dataset type); classify attributes as categorical, ordinal or quantitative and say whether ordered data is sequential, diverging or cyclic; choose the matching Altair type code; recognize tidy and untidy tables and convert between wide and long format with melt and pivot; load CSV and nested JSON with pandas and check dtypes; and write a data-quality report (duplicates, missing values, invalid values, inconsistent categories) before any chart is drawn.
Before choosing a chart, you must know what the data is — not its file name or its business meaning, but its abstract structure: which things are counted (items), what is measured about them (attributes) and what kind of values those measurements take. The same three columns can be a perfect line chart or a nonsense one depending on whether "month" is treated as text or as time. Data abstraction is the vocabulary that makes such decisions systematic — and it is exactly what AI tools get wrong when they guess types from column names.
Items, attributes and dataset types
- An item is one entity: a sensor reading, a bike trip, a building.
- An attribute (variable, field, dimension) is a property measured for each item: PM2.5, district, timestamp.
- A key identifies an item (sensor id + timestamp); values are the measured attributes.
Munzner distinguishes four basic dataset types:
| Type | Structure | CityPulse example |
|---|---|---|
| Table | items (rows) × attributes (columns); multidimensional tables have several keys | readings(sensor, timestamp → pm25, temperature) |
| Network / tree | nodes and links, both with attributes | stations (nodes) and trips between them (links) |
| Field | values sampled over a continuous space (grid cells) | interpolated PM2.5 over the city map |
| Geometry | shapes with explicit spatial positions | district boundaries (polygons), bus routes (lines) |
Plus collections: sets, lists and clusters. Data can also be static (a file) or dynamic (a stream that keeps arriving, like live bike status).
Attribute types
| Type | Meaning | Operations | Examples | Altair |
|---|---|---|---|---|
| Categorical (nominal) | names, no order | = ≠ | district, station, rider type | N |
| Ordinal | ordered, distances undefined | = ≠ < > | air quality level (good < moderate < unhealthy), survey scale | O |
| Quantitative | numbers with meaningful differences | + − (ratio: × ÷) | PM2.5, trip duration, energy | Q |
| Temporal | ordered time (quantitative with calendar semantics) | as above + calendar | timestamp, date | T |
Ordered data has an ordering direction: sequential (low → high, e.g., PM2.5), diverging (two directions from a meaningful midpoint, e.g., temperature anomaly around 0, change vs. last year) and cyclic (wraps around: hour of day, day of week, month, wind direction). The direction later decides the colour map (Chapter 6).
Be careful with numbers that are not quantities: a sensor id, a postal code or a station number is categorical — averaging sensor ids is meaningless. And quantities stored as text ("42 µg/m³") must be parsed before use.
Data semantics: time and space
Temporal attributes carry calendar structure: hours, weekdays, months, seasons, time zones and daylight-saving changes. Aggregating by "month" or comparing weekdays requires parsing timestamps into real date-times (pandas to_datetime). Spatial attributes (latitude/longitude, district names that match map polygons) enable maps (Chapter 10).
Derived attributes and granularity
Many useful attributes are not in the raw data but derived from it: hour of day and weekday from a timestamp, trip speed = distance / duration, fill rate = bikes / capacity, change vs. last year, a moving average. Deriving the right attribute is often the most important design decision — a chart of raw hourly readings over a year is noise; the same data aggregated to daily means, or derived as "days above the guideline per month", tells a story.
Every table also has a granularity (what one row means): one reading per sensor per hour, one trip, one building-month. Before aggregating, write it down. Two classic errors follow from ignoring it: double counting after a join that repeats rows (joining trips to an hourly weather table by date gives 24 copies of each trip), and averaging averages across groups of different sizes. A useful habit is to state, for every chart, "each mark represents …" (e.g., "each point is one district on one day").
Tidy data
Hadley Wickham's tidy data principles (2014):
- Each variable forms a column.
- Each observation forms a row.
- Each type of observational unit forms a table.
The table below is wide (untidy for analysis): months are values of a variable "month", but they are stored as column names.
| building | Jan | Feb | Mar |
|---|---|---|---|
| Library | 320 | 300 | 280 |
Its long (tidy) form has columns building, month, kwh — one row per (building, month). Grammar-of-graphics libraries like Altair expect long data: color="building:N", x="month:O", y="kwh:Q" only works if month and kWh are columns. In pandas: df.melt(id_vars="building", var_name="month", value_name="kwh") (wide → long) and long.pivot(index="building", columns="month", values="kwh") (long → wide, e.g., for a heat-map table or a report).
Other common untidiness: several variables in one column ("Lucheng_PM25"), variables in rows, one table mixing readings and sensor metadata (split into two tables and join on the key).
File formats
| Format | Good for | Pitfalls |
|---|---|---|
| CSV | universal, human-readable | no types (dates and ids become strings or floats), separators and encodings vary |
| JSON | APIs, nested records | must be flattened (pd.json_normalize) |
| Excel | business data | merged cells, several header rows, hidden sheets |
| Parquet | analytics, large data | binary; keeps types and is columnar and compressed |
| SQL database | shared, updated data | needs queries and connection management (Chapter 4) |
After loading, always check df.dtypes, df.shape, df.head() and df.describe().
Data quality before visualization
A chart of dirty data is a convincing lie. Standard checks:
- Duplicates — the same reading sent twice (
df.duplicated()). - Missing values —
NaN(sensor offline). Decide: drop, impute, or show the gap (often best: show it). - Invalid values — negative PM2.5, 2,400 µg/m³ from a broken sensor; define valid ranges with domain experts.
- Inconsistent categories — "Lucheng", " lucheng", "LUCHENG" are one district (
str.strip().str.title()). - Unparseable types — "not a date" in a timestamp column (
to_datetime(errors="coerce")then count NaT).
In Lab V2.3, 9 raw rows shrink to 4 valid ones (44 %) — a typical surprise. Report what you removed and why; it belongs in the methods of any project.
Data teams formalize these checks as data contracts and automated tests (e.g., Great Expectations, dbt tests, pandera schemas) that run every time new data arrives, so a broken sensor or a renamed API field is caught before a dashboard shows nonsense to managers.
AI systems that generate charts from natural language must first infer data semantics — which column is time, which is a category, which numbers are identifiers. Research on NL2VIS shows many failures start here, not in the drawing; tools such as Microsoft's LIDA therefore begin with a "data summary" step that describes each column's type and meaning before proposing charts.
Key takeaways
- Items × attributes; keys identify, values measure. Dataset types: tables, networks/trees, fields, geometry (+ sets, lists, clusters); static or dynamic.
- Attribute types: categorical (N), ordinal (O), quantitative (Q), temporal (T); ordered data is sequential, diverging or cyclic.
- Numeric-looking ids are categorical; text-looking quantities must be parsed.
- Tidy: variables = columns, observations = rows, one table per unit. Altair wants long data:
melt(wide → long),pivot(long → wide). - Check dtypes and data quality (duplicates, missing, invalid, inconsistent categories) and report what you cleaned.
Ready? Close the notes and practise.
30 questions. Predict the output before you check — that is the skill the exam measures.