Classify variables as categorical or numerical and choose the summary that fits each type.
Why this matters
Every statistical question starts with the same step: look at a column of data and decide what kind of thing it holds. That decision controls everything after it. You can average a column of temperatures, but you cannot average a column of blood types. A chart that works for counts of product categories looks wrong for weights. Analysts, lab technicians and engineers make this call dozens of times a day, usually without noticing. This lesson makes it explicit so you make it correctly.
Observations and variables
A dataset is usually a table. Each row is one observation (one patient, one sample, one bridge inspection, one website visit). Each column is a variable: something you measured or recorded about every observation.
| sample_id | material | batch_grade | tensile_mpa | defects |
|---|---|---|---|---|
| S-01 | steel | A | 412.5 | 0 |
| S-02 | aluminium | B | 276.0 | 2 |
| S-03 | steel | A | 405.1 | 1 |
sample_id is a label, not something to analyse. The other four columns are four different kinds of variable.
Categorical variables
A categorical (qualitative) variable puts each observation in a group.
- Nominal: groups with no natural order.
material(steel, aluminium), blood type, country, browser name. - Ordinal: groups with a meaningful order but no fixed distance between them.
batch_grade(A better than B better than C), survey answers from "strongly disagree" to "strongly agree", pain on a 1 to 5 scale.
Useful summaries for categorical data are counts, proportions (percent of the total) and the mode (the most common group). For ordinal data the median also makes sense, because you can line the answers up in order and find the middle one.
A common trap: numbers used as codes. A ZIP code, a phone number, an employee ID or a "region 1, 2, 3" column is categorical even though it is written with digits. The test is simple: would an average mean anything? The average ZIP code is nonsense, so ZIP code is categorical.
Numerical variables
A numerical (quantitative) variable is a measured or counted amount, where arithmetic makes sense.
- Discrete: counts that come in whole steps.
defects(0, 1, 2...), number of support tickets, number of colonies on a plate. - Continuous: measurements that can take any value in a range, limited only by the instrument.
tensile_mpa, temperature, time, concentration, mass.
For numerical data you can use the mean, median, standard deviation, range and percentiles, and charts like histograms and box plots. The next lesson covers those in detail.
Interval and ratio (a finer split)
Some textbooks split numerical data again:
- Interval: differences are meaningful but zero is arbitrary. Temperature in Celsius: 20 °C is not "twice as hot" as 10 °C.
- Ratio: there is a true zero, so ratios make sense. Mass, length, Kelvin temperature, money. 20 kg really is twice 10 kg.
You rarely need this distinction in day-to-day work, but it explains why "percent increase" is fine for revenue and misleading for Celsius.
Choosing a summary: a quick table
| variable type | example | centre | spread | chart |
|---|---|---|---|---|
| nominal | material | mode | counts per group | bar chart |
| ordinal | batch grade | median, mode | range of grades | ordered bar chart |
| discrete | defects | mean, median | standard deviation, range | bar chart or histogram |
| continuous | tensile strength | mean, median | standard deviation, IQR | histogram, box plot |
Worked example: a clinic visit log
A clinic records visit_reason (checkup, injury, illness), satisfaction (1 to 5 stars), wait_minutes and prescriptions (how many were written).
visit_reasonis nominal: report "45% checkups, 30% illness, 25% injury".satisfactionis ordinal: report the median (say 4 stars) and the share of 1 and 2 star ratings. A mean of 3.7 stars is often reported anyway, but be aware it assumes the gap between 1 and 2 stars equals the gap between 4 and 5.wait_minutesis continuous: report the median wait and the spread.prescriptionsis discrete: the mean (1.4 per visit) is fine, even though no single visit had 1.4.
How software sees types
Spreadsheets and Python do not know what your data means. A column of ZIP codes is stored as numbers, so the software will happily average it. In Python's statistics module, mean works on any list of numbers, and mode works on any list of hashable values, including text:
import statistics
materials = ["steel", "aluminium", "steel", "steel"]
print(statistics.mode(materials)) # steel
defects = [0, 2, 1, 0, 3]
print(statistics.mean(defects)) # 1.2
The software runs whatever you ask. Choosing the right summary is your job.
Common mistakes
- Averaging codes (IDs, ZIP codes, category numbers).
- Treating ordinal scales as if the steps were equal without saying so.
- Turning a continuous variable into categories ("old" vs "young") too early, which throws information away.
- Forgetting that the same quantity can be recorded at different levels: age in years is numerical, age group "18 to 24" is ordinal.
Quick recap
- Rows are observations; columns are variables.
- Categorical: nominal (no order) or ordinal (ordered). Summarise with counts, proportions, mode (and median for ordinal).
- Numerical: discrete (counts) or continuous (measurements). Summarise with mean, median, standard deviation and percentiles.
- Ask "would an average mean anything?" before you compute one.
Try it
Open the Do tab and classify the variables in the quiz.