Types of Data and Scales of Measurement

Why the average of a zip code means nothing, and how to tell which kinds of maths each column in your data can actually handle.

zip_code
Nominal
rating
Ordinal
temp_c
Interval
items
Ratio
02134Good31.53
10001Excellent28.01
90210Poor35.26
Three delivery orders, four columns. Every one of them is a number or could be stored as one, but only some of them can be averaged, and only one of them can be doubled. By the end of this article you'll know which, and why.

On Day 1 we met the two branches of statistics, descriptive and inferential. Today we step back and ask a more basic question: what kind of data are we even working with? The answer decides almost everything that comes after it.

Why data types matter

Before you run any analysis, fit any model, or compute any statistic, you need to understand the nature of your data. Using the wrong method for the wrong kind of data is one of the most common mistakes in data science. Computing the mean of a column of labels, like blood type stored as numbers, is mathematically possible. Python won't stop you. It's also completely meaningless.

Think of it like grammar

Data types are the grammar rules of statistics. A sentence can be perfectly spelled and still make no sense if a noun sits where a verb belongs. In the same way, a calculation can run without errors and still mean nothing, if you average numbers that were only ever labels.

Pythonimport pandas as pd df = pd.DataFrame({ "gender_code": [1, 2, 1, 1, 2], # 1 = Male, 2 = Female "age": [25, 31, 45, 29, 38] }) print("Mean gender_code:", df["gender_code"].mean()) print("Mean age: ", df["age"].mean())
OutputMean gender_code: 1.4 Mean age: 33.6

Pandas runs both without complaint. The mean age is genuinely useful. The mean gender code, 1.4, is nonsense: it describes nothing real about these five people, because "1" and "2" are just labels wearing number costumes. The fix is to tell pandas the truth about the column:

Pythondf["gender_code"] = df["gender_code"].astype("category") try: df["gender_code"].mean() except TypeError as e: print("Error:", e)
OutputError: 'Categorical' with dtype category does not support operation 'mean'

Once the column is typed as a category instead of a plain integer, pandas refuses to average it at all. That error is a feature, not a bug: the library is stopping you from doing exactly the meaningless thing this section opened with.

The two broad types of data

Every column in a dataset starts by answering one question: is it describing a kind of thing, or an amount of something?

Qualitative dataQuantitative data
NatureCategories, descriptionsNumbers that measure or count
Answers"What type?" or "Which category?""How many?" or "How much?"
ExamplesGender, cuisine type, blood groupAge, income, temperature
Key operationsFrequency counts, mode, and the median if the categories have an orderMean, variance, regression
All data Qualitative Quantitative Nominal blood type, city Ordinal ratings, education Discrete orders, clicks Continuous height, load time no arithmetic on the labels arithmetic is meaningful All data Qualitative Quantitative Nominal blood type, city Discrete orders, clicks Ordinal ratings, education Continuous height, load time no arithmetic arithmetic works
Each broad type splits again. Qualitative data is either nominal (no order) or ordinal (ordered). Quantitative data is either discrete (counted) or continuous (measured).

Qualitative (categorical) data

Qualitative data describes characteristics or categories. It's non-numeric by nature, even when it's stored as numbers for convenience (1 = Male, 2 = Female, say). Storing it as numbers doesn't make it numeric. You still can't meaningfully average a gender code, as the example above just showed.

Common examples: gender, colours, customer satisfaction levels (Satisfied, Neutral, Unsatisfied), types of animals, country of residence.

Qualitative data is mostly used to split data into groups for comparison: purchase rates across different customer age bands, say, or disease rates across blood types. As the diagram shows, it comes in two flavours: nominal, where the categories have no order at all (blood type), and ordinal, where they do (satisfaction levels). We'll look at both properly in the scales section below.

Quantitative (numerical) data

Quantitative data represents amounts. Unlike qualitative data, doing arithmetic on it actually means something.

Common examples: age (25, 30, 45 years), income ($50,000, $75,000), temperature (20°C, 30°C), number of website visits (100, 500, 1,000). Quantitative data splits into two important subtypes.

Discrete data

Discrete data consists of distinct, countable values, usually whole numbers. There are gaps between the possible values: you can't have a fraction of most real-world things you count.

Common examples: the number of students in a classroom (20 or 21, never 20.5), cars in a parking lot, customer complaints received in a day, defective products in a batch.

Continuous data

Continuous data can take any value within a range, including fractions and decimals. It's measured, not counted, and in principle there are infinitely many possible values between any two points.

Common examples: height (170.2 cm, 171.83 cm), weight (65.5 kg, 65.51 kg), temperature (23.4°C, 23.45°C), the time a webpage takes to load (1.237 seconds).

A quick way to tell them apart

If you're counting something, it's probably discrete. If you're measuring it with an instrument, it's probably continuous.

Two cases trip people up. Money is technically counted in the smallest unit (you can't pay half a paisa or half a cent), but amounts are usually so large and finely divided that analysts treat them as continuous. Age depends on how it was recorded: "how many full years old" is discrete, while exact age measured from a date of birth is continuous. When in doubt, ask how the number was produced.

Scales of measurement

Knowing how data is measured matters as much as knowing its type, because the scale decides which calculations are actually valid. The four scales used everywhere today come from a 1946 paper in the journal Science by the psychologist S. S. Stevens. They go from least to most information.

1. Nominal scale

The nominal scale sorts data into distinct, unordered categories. No category is "greater than" or "less than" another. The only meaningful comparison is: same category, or different?

Shirt numbers in a cricket or football team are a perfect example. A player wearing 10 isn't twice as good as one wearing 5, and the "average shirt number" of a team tells you nothing about anyone. The numbers are names.

Other examples: blood type (A, B, AB, O), network protocols (TCP, UDP, ICMP), types of cuisine, postal and zip codes, eye colour, marital status, country of origin.

Valid operations: frequency counts, the mode, and tests built for counts of categories, like the chi-square test.

A common mistake

Zip codes and PIN codes look like numbers, but their mean is nonsense. They're labels. Worse, software that treats them as numbers can quietly damage them, which turned out to matter a great deal in genetics research. That story is the third case study near the end of this article.

2. Ordinal scale

Ordinal data has a meaningful order, but the gaps between categories aren't necessarily equal. You know one value is higher than another, just not by how much.

Common examples: customer satisfaction (Poor, Fair, Good, Excellent), education level (High School, Bachelor's, Master's, PhD), disease severity (Mild, Moderate, Severe, Critical), survey answers from Strongly Disagree to Strongly Agree, and star ratings.

The clearest real example of unequal gaps comes from geology. In 1812 the mineralogist Friedrich Mohs ranked ten minerals by which can scratch which: talc is 1, diamond is 10. It's still widely taught and used today. But measure the minerals' actual hardness with an instrument, and the steps turn out to be wildly uneven:

Mohs rank absolute hardness 1 Talc 1 2 Gypsum 2 3 Calcite 14 4 Fluorite 21 5 Apatite 48 6 Orthoclase 72 7 Quartz 100 8 Topaz 200 9 Corundum 400 10 Diamond 1,500 From 9 to 10 is one Mohs step, but nearly four times the hardness. Mohs rank absolute hardness 1 Talc 1 2 Gypsum 2 3 Calcite 14 4 Fluorite 21 5 Apatite 48 6 Orthoclase 72 7 Quartz 100 8 Topaz 200 9 Corundum 400 10 Diamond 1,500 From 9 to 10 is one Mohs step, but nearly four times the hardness.
Absolute hardness values from a sclerometer, as listed in the Mohs scale reference table. Each Mohs step is "one more", but the real jump ranges from 1 unit to 1,100.

Going from topaz (8) to corundum (9) doubles the hardness. Going from corundum (9) to diamond (10) nearly quadruples it. Both are a single step on the Mohs scale. That's ordinal data in a nutshell: the order is real, but the numbers say nothing about the size of the gaps.

Valid operations: the median, percentiles, and rank-based methods like Spearman correlation and the Mann-Whitney U test, which compare positions rather than distances.

Why not the mean?

The gap between "Poor" and "Fair" may not be the same as the gap between "Good" and "Excellent". Averaging ordinal values quietly assumes the gaps are equal, which is the one thing ordinal data doesn't promise. Averaging Mohs numbers would make the same mistake on a much bigger scale.

Ordinal data has another trap in code. Nothing about the labels themselves carries their order:

Pythonratings = pd.Series(["Good", "Poor", "Excellent", "Fair", "Good", "Excellent"]) order = ["Poor", "Fair", "Good", "Excellent"] ranked = ratings.astype(pd.CategoricalDtype(categories=order, ordered=True)) print("Alphabetical sort:", sorted(ratings.tolist())) print("Semantic sort: ", ranked.sort_values().tolist())
OutputAlphabetical sort: ['Excellent', 'Excellent', 'Fair', 'Good', 'Good', 'Poor'] Semantic sort: ['Poor', 'Fair', 'Good', 'Good', 'Excellent', 'Excellent']

Sorted alphabetically, "Excellent" comes before "Poor" because E comes before P. Nobody means that by a satisfaction rating. Telling pandas the real order fixes it, which is why ordinal data always needs its order spelled out.

Now try the operation the callout warned about:

Pythontry: ranked.mean() except TypeError as e: print("mean() fails:", e)
Outputmean() fails: 'Categorical' with dtype category does not support operation 'mean'

Pandas won't even let you try. Interestingly, it also refuses .median() on a categorical column, even though the median is valid for ordinal data. To get it, you go through the category codes (Poor = 0, Fair = 1, Good = 2, Excellent = 3) and translate back to a label. There's one catch to handle: with an even number of ratings, the middle can fall exactly between two categories.

Pythondef ordinal_median(s): m = s.cat.codes.median() cats = s.cat.categories if m == int(m): return cats[int(m)] # the middle falls between two categories, so say so return f"between {cats[int(m)]} and {cats[int(m) + 1]}" four = pd.Series(["Poor", "Fair", "Good", "Excellent"]).astype(ranked.dtype) print("Six ratings: ", ordinal_median(ranked)) print("Four ratings:", ordinal_median(four))
OutputSix ratings: Good Four ratings: between Fair and Good

For the four ratings, the median code is 1.5. A quick shortcut like order[int(median_code)] would silently round that down and report "Fair", which isn't the middle at all. The honest answer is "between Fair and Good". The order is meaningful enough to find a middle, but the labels aren't numbers, so you can't invent a category halfway between two of them.

3. Interval scale

Interval scales have order and equal spacing: the distance between any two neighbouring values is the same everywhere on the scale. What they lack is a true zero. Zero on an interval scale is a point someone chose, not the absence of the thing being measured.

Because the spacing is equal, adding and subtracting work: you can say today is 5 degrees warmer than yesterday. Because the zero is arbitrary, multiplying and dividing don't: you can't say one value is twice another.

Temperature in Celsius or Fahrenheit is the classic case. 0°C is simply the freezing point of water, not "no temperature". In fact, when Anders Celsius proposed his scale in 1742, he put 0 at the boiling point and 100 at freezing. It was flipped to today's version within a couple of years. A zero that can be moved to the other end of the scale is clearly a human choice.

So is 40°C twice as hot as 20°C? Physically, no. Temperature in the physical sense is measured from absolute zero, the true zero of the kelvin scale. 20°C is 293.15 K and 40°C is 313.15 K, and 313.15 is only about 1.07 times 293.15:

Measured from 0 °C (a zero someone chose) 20 °C 40 °C looks like 2 times Measured from 0 K (absolute zero, a true zero) 293.15 K 313.15 K really about 1.07 times (20 °C) (40 °C) Measured from 0 °C (a zero someone chose) 20 °C 40 °C looks like 2 times Measured from 0 K (absolute zero, a true zero) 293 K 313 K really about 1.07 times
The same two temperatures, measured from two different starting points. The "twice as hot" impression comes entirely from where Celsius happens to put its zero.

This is true of any pair of Celsius or Fahrenheit temperatures, not just these two. Ratio claims need a zero that means "none of it", and neither scale has one.

Calendar years work the same way. The gap from 2000 to 2010 is the same as from 2010 to 2020, but the starting point of the calendar is a convention, not the beginning of time. The year 2000 isn't "twice" the year 1000 in any meaningful sense.

Valid operations: the mean, the standard deviation, Pearson correlation, t-tests, and ANOVA. (Several of these get their own days later in the series.) Ratios and anything built on them, like the coefficient of variation, are off limits.

Borderline cases you'll meet

IQ scores and standardised test scores (SAT, GRE) are often listed as interval data, and in practice they're analysed that way. But many researchers argue they're really ordinal: there's no guarantee the difference between scores of 100 and 110 means the same as between 130 and 140. The same debate surrounds survey ratings and pain scales, which we'll come back to in the hospital case study. Treat these as judgement calls, not settled facts.

4. Ratio scale

Ratio scales have everything interval scales have, plus a true zero: zero means none of the thing at all. That makes ratios meaningful, so you can genuinely say one value is twice another.

Valid operations: everything, including ratios, the geometric mean, and the coefficient of variation, which gets its own article on Day 5 because it's one of the most useful things a true zero buys you.

categories only Nominal blood type, zip code + order Ordinal satisfaction rating + equal spacing Interval temperature in °C + true zero Ratio income, file size Nominal categories only blood type, zip code Ordinal + order satisfaction rating Interval + equal spacing temperature in °C Ratio + true zero income, file size
Each scale keeps everything the one before it could do, and adds one more ability. Ratio data can do everything nominal data can, plus order, equal spacing, and a true zero.
The scale depends on how you record it

A scale isn't fixed to the quantity itself. It depends on how the number was captured. Temperature in kelvin is ratio data, but the same temperature in Celsius is interval. Income recorded in rupees is ratio data, but many surveys only ask which bracket you fall into ("below 5 lakh, 5 to 10 lakh, above 10 lakh"), and those brackets are ordinal: you know the order, but the brackets aren't equal in width and you can't average them. So when you get a dataset, look at how each column was actually collected, not just what it's called.

The four scales at a glance

ScaleOrderEqual gapsTrue zeroMiddle value you can useExample
NominalNoNoNoModeBlood type, zip code
OrdinalYesNoNoMedian, modeSatisfaction rating, Mohs hardness
IntervalYesYesNoMean, median, modeTemperature in °C, calendar year
RatioYesYesYesAll of them, plus ratiosIncome, height, file size

Each row builds on the one before it. Ratio data is the richest of the four and nominal the most limited. The "middle value" column is a preview of Day 3, which is all about the mean, median and mode.

Case studies

The first two case studies are typical datasets, built to show how one table can mix every scale. The third is a real story about what happens when software gets a column's type wrong.

Case study 1: e-commerce product feedback

A company collects customer feedback on a new product launch.

VariableData typeScaleAppropriate analysis
Customer genderQualitativeNominalFrequency counts, mode
Satisfaction ratingQualitativeOrdinalMedian, mode, Mann-Whitney U
Time on site (minutes)Quantitative (continuous)RatioMean, standard deviation, regression
Year of purchaseQuantitativeIntervalTrends over time

Notice how the right analysis changes with the scale, not just the type. "Year of purchase" and "time on site" are both quantitative, but one is interval (the calendar's starting point is a convention) and the other is ratio (zero minutes genuinely means no time spent). That's why identifying scales, not just types, comes first.

Case study 2: hospital patient records

A hospital records patient data for a research study.

VariableData typeScaleAppropriate analysis
Blood typeQualitativeNominalChi-square test, rates by group
Pain score (0 to 10)Debated (see below)Ordinal, often treated as intervalRank-based tests if treated as ordinal
Body temperature (°C)Quantitative (continuous)IntervalMean, t-tests
Number of hospital visitsQuantitative (discrete)RatioRegression, Poisson modelling
On pain scores and rating scales

Hospitals commonly ask patients to rate pain from 0 to 10. Strictly, that's ordinal: the jump from 1 to 2 may not feel like the jump from 8 to 9. In practice, many researchers treat it as interval so they can use means and t-tests, and statisticians have argued about whether that's acceptable for decades. The same argument applies to the agree/disagree survey scales you'll see everywhere. Whichever way you go, say so and give a reason. Nobody will fault you for the judgement call. They will fault you for not mentioning you made one.

Case study 3: when Excel renamed human genes

Geneticists name genes with short codes. One family of genes is called septins, so its genes are SEPT1, SEPT2 and so on. Another gene is called MARCH1. These names are nominal data: pure labels.

Excel, trying to be helpful, saw "SEPT2" and "MARCH1" and decided they were dates. Type them into a cell with default settings and they turn into "2-Sep" and "1-Mar". Some gene identifiers made of digits and a letter were converted into numbers instead: one became 2.31E+13.

In 2016, the researchers Ziemann, Eren and El-Osta checked the Excel gene lists published alongside papers in 18 journals from 2005 to 2015. Of 3,597 papers with such lists, 704, about 20%, contained gene names that had been mangled this way. The problem was serious enough that in 2020 the committee that names human genes renamed some of them: SEPT1 became SEPTIN1 and MARCH1 became MARCHF1, so that spreadsheets would leave them alone.

The lesson is the same one as the zip codes, at a much bigger scale: a column's type has to be decided by a person who knows what it means, not guessed by software from what it looks like. Pandas guesses too. Here's what happens to zip codes with a leading zero:

Pythonimport io csv = "zip_code,orders\n02134,3\n10001,5\n90210,2\n" df = pd.read_csv(io.StringIO(csv)) print("Default read:", df["zip_code"].tolist()) # tell pandas this column is a label, not a number df = pd.read_csv(io.StringIO(csv), dtype={"zip_code": str}) print("Read as text:", df["zip_code"].tolist())
OutputDefault read: [2134, 10001, 90210] Read as text: ['02134', '10001', '90210']

The default read turned "02134" into the number 2134 and lost the zero for good. Reading the column as text keeps it intact. Any column that's really an identifier (zip codes, phone numbers, account numbers, product codes) should be read as text.

Key takeaway

Whenever you get a new dataset, identify the type and scale of every column first, before computing a single summary statistic. For each column, ask:

  1. Is this qualitative or quantitative?
  2. If quantitative, is it discrete or continuous?
  3. Which scale is it on: nominal, ordinal, interval, or ratio? And does that depend on how it was recorded?

This checklist guides every decision that follows, from which summary statistics make sense to how you prepare data for machine learning. A nominal column like blood type usually needs one-hot encoding (one yes/no column per category) before most models can use it, because feeding in raw category codes would suggest an order and a distance between categories that don't exist. An ordinal column can often keep a single encoding that preserves its order. Interval and ratio columns can go in as they are, though models that are sensitive to scale, like k-nearest neighbours or anything trained with gradient descent, usually need them rescaled first. Three different choices, and the scale is what decides between them.

Quick check

Four questions to test whether this stuck. The answers are one click away.

A hospital ID like "PT-04821" contains digits. What scale is it on?

Nominal. The digits are part of a label, not a quantity. There's no meaningful order between PT-04821 and PT-04822, and averaging IDs would be the same mistake as averaging zip codes. It should be read and stored as text.

Can you average a week of temperatures recorded in Fahrenheit? Can you say 80°F is twice as warm as 40°F?

Yes to the first, no to the second. Fahrenheit is an interval scale, so the mean is perfectly valid: equal spacing means "the average was 61°F this week" makes sense. But ratios need a true zero, which Fahrenheit doesn't have. Converted to kelvin, 40°F is about 277.6 K and 80°F is about 299.8 K, a ratio of roughly 1.08, nowhere near 2.

A column holds "number of support tickets per customer". What type and scale is it?

Quantitative and discrete (3 tickets or 4, never 3.5), on a ratio scale: 0 tickets genuinely means no tickets, and 6 tickets is genuinely twice 3.

A survey records income as "below 5 lakh", "5 to 10 lakh" or "above 10 lakh". Can you calculate the average income from it?

No. Income itself is ratio data, but recorded this way it's ordinal: the brackets have an order, but they aren't equal in width and the top one has no upper limit. You can report the most common bracket or the bracket the median falls in, but not a mean. The scale comes from how the data was collected.

Next up, Day 3 Measures of Central Tendency

The mean, median and mode in depth: how each one is calculated, when to use which, and how outliers and skewed data can make an average mislead you.