Contents/ Part I ยท Foundations/ Chapter 4

Types of Data & Variables

Before you can analyze anything, you need to know what kind of data you're holding. The type of a variable quietly decides every chart, statistic, and model you're allowed to use.

โฑ๏ธ ~11 min read
๐Ÿ Notebook included
๐Ÿ“Š Chapter 4

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?"

๐Ÿท๏ธ
Why it matters: the data type determines which charts, summary statistics, and tests & models are valid. Compute an "average eye color" and you've made a type error, not a math one.
1

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:

VARIABLES Categorical (Qualitative) Numerical (Quantitative) Nominal no order eye color, gender Ordinal has an order S < M < L, ratings Discrete counts # children, goals Continuous measures height, time, temp
ACategorical (Qualitative)

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)
BNumerical (Quantitative)

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)
โš–๏ธ
The special case: binary variables

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.

โš ๏ธ
The classic trap

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.

2

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.

๐Ÿงช
Quick test

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.

๐Ÿ”
The fuzzy cases

"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.

3

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 Variable the CAUSE, e.g., study hours influences Dependent Variable the EFFECT, e.g., exam score

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.

๐Ÿ”‘
Why confounders are the famous one

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.

4

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.

โžก๏ธ
Coming next

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 Notebook (code & outputs) โ–ถ Open in Colab โฌ‡ View / Download on GitHub

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.
5

Practice Challenges

Four short challenges covering the chapter's core ideas. Beginner-friendly, try them on paper or in Python.

1

Classify each variable

For each, give the big type and subtype: age, eye color, number of siblings, temperature, T-shirt size (S/M/L).

Hint: first ask "is it a number you'd do math on?", then "counted or measured?" / "ordered or not?"
2

Split the columns

A table has city, age, plan, monthly_$. List which columns are qualitative and which are quantitative.

Hint: text categories vs. numbers you can average.
3

Discrete or continuous?

Label each: cars in a parking lot, weight of a parcel, goals scored, time to run 5 km.

Hint: can the value always gain one more decimal place?
4

Find the roles

Study: "Does the amount of fertilizer affect plant height?" Identify the independent variable, the dependent variable, and one possible confounder.

Hint: what do we change, what do we measure, and what else could affect the result?
โœ…
Check your work

A fully-worked solutions notebook walks through all four challenges in the same visual style, try them yourself first, then compare.

๐Ÿ““ View Solutions โ–ถ Open Solutions in Colab โฌ‡ View / Download on GitHub
6

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.