A variable is simply a characteristic that can take different values: height, gender, temperature, satisfaction. The values you collect for it are your data. And the very first question a data scientist asks about any column is: "what type is this?"
The Big Split: Qualitative vs. Quantitative
Every variable belongs to one of two big families, and each family splits again. The whole map on one page:
Describes qualities or groups. You can count how many fall in each group, but math like "average" makes no sense.
- Nominal, labels with no order (eye color, country, gender)
- Ordinal, ordered categories (small/medium/large, 1โ5 stars)
Represents numbers you can do math on, add them, average them, measure spread.
- Discrete, countable values, often whole numbers (number of cars, goals scored)
- Continuous, any value in a range (height, weight, temperature)
A variable with exactly two categories (yes/no, pass/fail, spam/not-spam) is called binary or dichotomous. It is the most common categorical type in data science, and a handy trick is to code it as 0/1, because then its average is simply the proportion of 1s. That single idea powers logistic regression later in the book.
Numbers aren't always quantitative. A jersey "number 10" or a zip code are just labels (nominal), averaging them is meaningless. In real datasets, categories are often stored as numbers (1 = male, 2 = female), so you can't tell the type from the values alone, you need the codebook (the data dictionary). Always ask what the number represents, not just whether it looks numeric.
Discrete vs. Continuous
Within numerical data, this distinction shapes which chart and which distribution you'll use. The test is simple: do you count it, or measure it?
Discrete, you count it
Separate, countable values, usually whole numbers. Between 2 children and 3 children there's nothing in between. Shown with separated bars.
Examples: number of pets, goals scored, students in a class.
Continuous, you measure it
Any value within a range, limited only by your instrument's precision. There's always a value between any two. Shown with a histogram.
Examples: height, weight, time, temperature.
Can a value always have one more decimal place (2.5 kg โ 2.53 kg โ 2.531 kg)? If yes, it's continuous. If the in-between values are impossible (2.5 children?), it's discrete.
"Discrete" means countable, not strictly whole-number: shoe sizes (7, 7.5, 8) are discrete yet not integers. And it can depend on how a value is recorded: money is conceptually continuous but stored in whole cents, and age is continuous but usually recorded in whole years. When in doubt, ask what the value is, then how it was measured.
Variable Roles: Cause, Effect & the Rest
Beyond type, every variable also plays a role in a study. The two stars are the independent and dependent variables:
Independent (IV)
The variable you change or suspect is the cause. "What we vary."
Dependent (DV)
The outcome you measure, it depends on the IV. "What we observe."
Control
Held constant so it can't muddy the result (e.g., same soil for every plant).
Confounding
A hidden variable that affects both IV and DV, faking a relationship (ice cream & drownings โ temperature).
Moderator
Changes the strength of the IVโDV link (a drug works better for younger patients).
Mediator
The mechanism in between, IV โ mediator โ DV (exercise โ fitness โ mood).
Going further: the first four roles are the everyday essentials. Moderator and mediator are a step more advanced and show up mainly in research design and regression, so don't worry if they take a second read.
A confounder is exactly why "correlation โ causation." Two variables can move together only because a third is secretly driving both. We'll meet this again in the Correlation chapter.
Why the Type Decides Everything
Get the type right and the correct tools follow automatically:
The right chart
Categorical โ bar/pie. Continuous โ histogram/box plot. Two numbers โ scatter.
The right summary
Numbers โ mean & standard deviation. Categories โ counts, proportions, mode.
The right test/model
The data type drives the choice of statistical test and which models even apply.
We touched on nominal vs. ordinal here. The next chapter, Levels of Measurement, sharpens this into the four classic scales, nominal, ordinal, interval, and ratio, and exactly what math each one allows.
Bring it to life in Python
The companion notebook classifies the columns of a real table, picks the right chart for each type, contrasts discrete vs. continuous, and exposes a famous confounder in action.
View opens the rendered notebook instantly (no setup). Open in Colab runs &
edits it live in your browser. To run locally, install numpy, pandas, matplotlib
and launch jupyter notebook.
๐ Key Takeaways
- โTwo families: categorical/qualitative (nominal, ordinal) and numerical/quantitative (discrete, continuous).
- โDiscrete = counted (countable values, often whole numbers); continuous = measured (any value in a range).
- โNumbers can be categories, jersey numbers and zip codes are nominal labels, not quantities.
- โVariable roles: independent (cause) โ dependent (effect), plus control, confounding, moderator, and mediator.
- โType decides the toolkit, the chart, the summary statistic, and the test/model you may use.
Practice Challenges
Four short challenges covering the chapter's core ideas. Beginner-friendly, try them on paper or in Python.
Classify each variable
For each, give the big type and subtype: age, eye color,
number of siblings, temperature, T-shirt size (S/M/L).
Split the columns
A table has city, age, plan, monthly_$.
List which columns are qualitative and which are quantitative.
Discrete or continuous?
Label each: cars in a parking lot, weight of a parcel,
goals scored, time to run 5 km.
Find the roles
Study: "Does the amount of fertilizer affect plant height?" Identify the independent variable, the dependent variable, and one possible confounder.
A fully-worked solutions notebook walks through all four challenges in the same visual style, try them yourself first, then compare.
Quiz: Test Yourself
Eight quick questions to lock in data and variable types. Answer them, hit Check Answers, and keep refining until you score 100%. Your progress is saved, so you can hop back to the chapter and return anytime.