Statistics for Data Science · Day 2

Types of Data & Scales of Measurement

Know your data: types, scales, and why they drive every analytical decision.

By Shikhar · Series continued · ~12 min read

In Day 1, we looked at the two branches of statistics, descriptive and inferential. Today we take a 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 statistical method for the wrong data type is one of the most common mistakes in data science. Computing the mean of a nominal variable, like blood type, is mathematically possible. Python won't stop you. It's also completely meaningless.

Think of it this way

Data types are the grammar rules of statistics. Just as you wouldn't use an adjective where a verb is needed, you shouldn't apply a parametric test where ordinal data calls for a non-parametric one.

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 doesn't describe anything real about this group of five people, because "1" and "2" here 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 message is a feature, not a bug: it's the library stopping you from doing the exact thing the article opened with, computing the mean of a nominal variable.

The two broad types of data

Data broadly falls into two categories.

Qualitative dataQuantitative data
NatureCategorical, descriptiveNumeric, measurable
Answers"What type?" / "Which category?""How many?" / "How much?"
ExamplesGender, cuisine type, blood groupAge, income, temperature
Key operationsFrequency counts, modeMean, variance, regression
All data Qualitative gender, blood type, cuisine Quantitative Discrete Continuous number of orders height, time, temp
Every column in a dataset starts by answering one question: qualitative or quantitative? Quantitative then splits again into discrete or continuous.

Qualitative (categorical) data

Qualitative data describes characteristics or categories, and it's non-numeric by nature, even when it's sometimes encoded as numbers for computational purposes (1 = Male, 2 = Female, say). Encoding doesn't make it numeric. You still can't meaningfully compute the average of a gender code, as the example above just showed.

Common examples: gender (Male, Female, Other), colors (Red, Blue, Green), customer satisfaction levels (Satisfied, Neutral, Unsatisfied), types of animals (Dog, Cat, Bird), country of residence.

Qualitative data is most commonly used to segment and group data for comparison, for instance comparing purchase rates across different customer age groups, or disease prevalence across blood types.

Quantitative (numerical) data

Quantitative data represents numeric values that measure quantities or amounts. Unlike qualitative data, arithmetic operations on it are actually meaningful.

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 then splits into two important subtypes.

Discrete data

Discrete data consists of distinct, countable values, typically whole numbers. There are gaps between possible values: you simply can't have fractional counts of most real-world things.

Common examples: number of students in a classroom (you can have 20 or 21, but never 20.5), number of cars in a parking lot, number of customer complaints received in a day, number of 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 there are theoretically infinite 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), time taken to load a webpage (1.237 seconds).

Quick distinction

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

Scales of measurement

Knowing how data is measured matters just as much as knowing its type. The scale determines which statistical operations are actually valid. There are four scales, in increasing order of information richness.

1. Nominal scale

The nominal scale classifies data into distinct, unordered categories. There's no inherent ranking: one category isn't "greater than" or "less than" another. The only meaningful comparison is equality, is this the same category or a different one.

It's purely categorical, has no order or ranking, and only equality or inequality comparisons are valid.

Common examples: blood type (A, B, AB, O), network protocol types (TCP, UDP, ICMP), types of cuisine (Italian, Chinese, Mexican), zip or postal codes (numbers used as labels, not values), eye color, marital status, country of origin.

Valid operations: frequency counts, mode, chi-square tests.

A common mistake

Zip codes look like numbers, but computing their mean or average is nonsensical. They're labels, nominal data, despite the digits.

2. Ordinal scale

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

Its categories are ordered, the intervals between ranks aren't uniform or guaranteed to be equal, and ratios or arithmetic differences aren't meaningful.

Common examples: customer satisfaction ratings (Poor → Fair → Good → Excellent), education level (High School → Bachelor's → Master's → PhD), disease severity (Mild → Moderate → Severe → Critical), survey responses (Strongly Disagree → Disagree → Neutral → Agree → Strongly Agree), movie ratings (1 star → 5 stars).

Valid operations: median, percentile calculations, non-parametric tests like the Mann-Whitney U test and Spearman correlation.

Why not the mean?

The gap between "Poor" and "Fair" may not be the same as the gap between "Good" and "Excellent." Averaging ordinal ranks assumes equal spacing, an assumption you can't actually justify.

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. That's obviously not the order anyone means by a satisfaction rating. Telling pandas the real order fixes it, and this is exactly why ordinal data needs its order defined explicitly, nothing about the labels themselves carries it.

Now try the operation the "why not the mean" callout above 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() directly on a categorical column, even though the median is the operation the article lists as valid for ordinal data. To get it, you work with the underlying category codes and map the result back to a label:

pythonmedian_code = ranked.cat.codes.median() print("Median rating:", order[int(median_code)])
OutputMedian rating: Good

That extra step is the whole point of ordinal data in one line of code: the order is meaningful enough to find a middle value, but the labels themselves aren't numbers, so you have to translate through the codes and back.

3. Interval scale

Interval scales have ordered categories with equal, meaningful intervals between values. The key distinction from ordinal: the distance between values is consistent. However, there's no true zero point, and zero on an interval scale doesn't mean "absence" of the quantity.

It's quantitative with equal spacing between values, zero is arbitrary and doesn't indicate absence, and addition and subtraction are meaningful while multiplication and division aren't.

Valid operations: mean, standard deviation, Pearson correlation, t-tests, ANOVA.

4. Ratio scale

Ratio scales have all the properties of interval scales, plus a true and meaningful zero point: zero means the complete absence of the quantity. This makes ratios fully meaningful. You can genuinely say one value is twice another.

A true zero indicates absence, all arithmetic operations are valid, and ratios between values are meaningful.

Valid operations: all statistical operations, including geometric mean, coefficient of variation, and ratio calculations. (Coefficient of variation gets its own day later in this series, since it's one of the more useful tricks a true zero point buys you.)

categories only Nominal blood type, gender + order Ordinal satisfaction rating + equal spacing Interval temperature °C, IQ + true zero Ratio income, height
Each scale keeps everything the one before it could do, and adds one more capability. Ratio data can do everything nominal data can, plus order, equal spacing, and a true zero.

The four scales at a glance

ScaleOrderEqual intervalsTrue zeroExample
Nominal✗✗✗Blood type, gender
Ordinal✓✗✗Satisfaction rating, education level
Interval✓✓✗Temperature (°C), IQ score
Ratio✓✓✓Income, height, file size

Each row builds on the one before it. Ratio data is the richest of the four, nominal the most limited, and every scale in between inherits everything the previous one could do.

Real-world case studies

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, std dev, regression
Year of purchaseQuantitativeIntervalTime series trend analysis

Notice how the analysis approach changes completely depending on the scale, not just the type. "Year of purchase" and "time on site" are both quantitative, but one is interval (no true zero, since there's no "year zero" in any meaningful sense) and the other is ratio (zero minutes genuinely means zero time spent). That difference is exactly why identifying scales correctly, not just types, is a non-negotiable first step.

Case study 2: hospital patient records

A hospital records patient data for a research study.

VariableData typeScaleAppropriate analysis
Blood typeQualitativeNominalChi-square, disease prevalence by group
Pain severity (1–10)Qualitative / quantitative*Ordinal (or interval)Non-parametric tests if ordinal
Body temperature (°C)Quantitative (continuous)IntervalParametric tests, t-tests
Number of hospital visitsQuantitative (discrete)RatioRegression, Poisson modeling
* On pain severity

This one is genuinely debated. Technically it's ordinal, since the gap between "1" and "2" may not equal the gap between "8" and "9." In practice, many researchers treat it as interval for ease of analysis. Whichever you choose, note it and justify it. Nobody will fault you for the judgment call. They will fault you for not mentioning you made one.

Key takeaway and a practical tip

Whenever you get a new dataset, make identifying data types and scales your very first step, even before computing a single summary statistic. Ask yourself, for each column:

  1. Is this qualitative or quantitative?
  2. If quantitative, is it discrete or continuous?
  3. What scale does it belong to: nominal, ordinal, interval, or ratio?

This three-question checklist guides every analytical decision downstream of it, from which summary statistics are meaningful to compute (Day 1's territory) to which machine learning algorithms are even appropriate to use. A nominal column like blood type usually needs one-hot encoding before a model can use it at all, since feeding in raw category codes would falsely imply an order and distance between categories that don't exist. An ordinal column can often use an encoding that preserves its order. Interval and ratio columns mostly just need scaling. Three very different choices, and the scale of the data is what decides between them.

Quick check

Three questions to test whether this stuck.

A hospital ID number, like "PT-04821," looks numeric. What scale is it actually on?

Nominal. The digits are a label, not a quantity. There's no meaningful order between PT-04821 and PT-04822, and averaging them would be exactly the same mistake as averaging zip codes.

Why can't you compute a meaningful average temperature in Fahrenheit and compare it directly to "twice as warm" claims?

Because Fahrenheit, like Celsius, is an interval scale: it has equal spacing between degrees, but its zero point is arbitrary rather than a true absence of heat. Ratio statements like "twice as much" require a true zero, which only Kelvin actually has among temperature scales.

A dataset has a column called "number of support tickets per customer." What type and scale is it?

Quantitative, discrete (you can have 3 tickets or 4, never 3.5), and ratio scale (0 tickets genuinely means no tickets, and 6 tickets is genuinely twice 3 tickets).

Up next in the series

Measures of Central Tendency: mean, median, and mode in depth, when to use each, and how outliers can deceive you.