Learning outcomes
By the end of this lesson you should be able to: define a dataset as a set of observations and variables; tell a numerical variable from a categorical one; and explain why the distinction between these two kinds of variable decides every tool you will use for the rest of the course.
Prerequisites
None. This is the first lesson. You need no statistics background, and no special software — every example uses tiny datasets you can read by hand, with the numbers confirmed in code.
The big idea
Statistics is not math for its own sake. It is a way of turning a messy pile of observations into a defensible claim. The very first skill is therefore not a formula but a habit of mind: looking at a dataset and correctly classifying what each column of it really is. Almost every mistake later in the course traces back to treating a variable as the wrong kind of thing. If you classify a variable correctly at the start, the correct tool for it almost picks itself.
Why this matters before any formula
The fundamental split in data is between numerical and categorical variables. A numerical variable is one recorded as a number with an order and quantity to it — an age, a height, a score. You can meaningfully average it. A categorical variable is one that records a label or a group — a gender, a blood type, an answer like yes or no. You cannot average it in a meaningful way; you can only count how often each category appears.
This split is a sorting fork. If a variable is numerical, you get tools like the mean, the median, and a histogram. If it is categorical, you get tools like a bar chart, a proportion, and later a chi-square test. Using the wrong family of tools is the single most common beginner error. Averaging a categorical variable like a gender code produces a number that sounds meaningful and is not. Reaching for a bar chart on a continuous numerical variable throws away the very ordering that made it useful.
There is a friendly middle ground worth knowing now: an ordinal variable sits between the two. It is recorded as a label with a natural order — a rating from poor to excellent, a class standing. You can meaningfully say one is better than another, but you should not assume the gaps are equal. Recognising this third kind now will save you later when a dataset hands you something that looks numeric but actually encodes a ranked judgement.
Worked example 1: reading a small dataset
Here is a very small dataset. Carefully identify the observations and the variables before you read anything else.
| name | gender | gpa | has_pet |
|---|---|---|---|
| Aiden | male | 3.9 | yes |
| Ayn | female | 3.7 | yes |
| Cevin | male | 3.4 | no |
Each row is one observation — here, one student. The columns are the variables recorded about that student: their name, gender, GPA, and whether they own a pet. Run your eye across a single row and you have all the measurements for one case; that is the unit of record in a dataset. The rows grow as you add observations, but the variables stay fixed, and that constancy is what lets you compare many rows at once.
Worked example 2: classifying the variables
Decide the kind of each variable. The code below prints each variable's values so the classification is visible rather than asserted.
data = [
{"gender": "male", "gpa": 3.9, "has_pet": True},
{"gender": "female", "gpa": 3.7, "has_pet": True},
{"gender": "male", "gpa": 3.4, "has_pet": False},
]
print("observations:", len(data))
print("numerical (gpa):", [d["gpa"] for d in data])
print("categorical (gender):", [d["gender"] for d in data])
print("categorical (has_pet):", [d["has_pet"] for d in data])observations: 3
numerical (gpa): [3.9, 3.7, 3.4]
categorical (gender): ['male', 'female', 'male']
categorical (has_pet): [True, True, False]There are three observations, and three variables are recorded on each. The GPA column is numerical — you can average the values, and doing so gives a meaningful summary. The gender column is categorical — the entries are labels, not quantities, so the summary is a count of how many students are male and how many are female. The has_pet column is also categorical, recorded as a true/false label; even though it is stored in a boolean, it is a category, not a measured quantity. That is the key habit: judge a variable by whether it is a measured amount or a label, not by how the computer happens to store it.
Common mistakes
Watch outAveraging a categorical variable. Computing the mean of a gender code or a yes/no flag produces a number that sounds like an answer and means nothing. Count categories instead.
Watch outAssume the computer stores things like we think about them. A category encoded as 0 and 1, or a true/false column, is still categorical. Classify by what the values mean, not how they are typed.
Watch outMistaking an ordinal variable for a true numerical one. A rating of poor/fair/good is ordered but its gaps are not necessarily equal, so averaging it is usually misleading.
Watch outIgnoring the unit of observation. A dataset of students and a dataset of classes both have numeric columns, but the tools you use differ depending on what a single row represents. State the observation first.
Check your understanding
In this dataset, each row is a student. What is the observation, and in general what is an observation in a dataset?
A column records students' ratings as 'beginner', 'intermediate' or 'advanced'. Is it numerical, categorical, or ordinal, and why?
Why does classifying a variable correctly matter for the rest of the course and its tools?
Multiple choice
Which best describes an observation in a dataset?
A dataset records students' heights in centimetres. What kind of variable is height?
Which variable is categorical?
What is the main risk of averaging a categorical variable?
A variable is recorded as a rating from poor to excellent. This is best described as:
Which tool is appropriate for summarising a numerical variable?
A column stores 0 for male and 1 for female. What kind of variable is it, and why?
When reasoning about data, what should you identify before choosing any tool?
Summary and next
A dataset is a collection of observations (rows) with variables (columns) measured on each. The crucial first classification is numerical versus categorical, with ordinal as the ordered middle ground. Getting this right selects the correct tool and avoids the meaningless-result trap of averaging a label.
Next: summarizing the center. Lesson 1 introduced variables; the next lesson shows how to summarise a numerical variable's typical value with the mean and the median — and why two very different answers often come from the same data.