Know your data: types, scales, and why they drive every analytical decision.
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.
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.
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.
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:
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.
Data broadly falls into two categories.
| Qualitative data | Quantitative data | |
|---|---|---|
| Nature | Categorical, descriptive | Numeric, measurable |
| Answers | "What type?" / "Which category?" | "How many?" / "How much?" |
| Examples | Gender, cuisine type, blood group | Age, income, temperature |
| Key operations | Frequency counts, mode | Mean, variance, regression |
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 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 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 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).
If you're counting something, it's likely discrete. If you're measuring it with an instrument, it's likely continuous.
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.
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.
Zip codes look like numbers, but computing their mean or average is nonsensical. They're labels, nominal data, despite the digits.
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.
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.
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:
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:
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.
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.
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.)
| Scale | Order | Equal intervals | True zero | Example |
|---|---|---|---|---|
| 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.
A company collects customer feedback on a new product launch.
| Variable | Data type | Scale | Appropriate analysis |
|---|---|---|---|
| Customer gender | Qualitative | Nominal | Frequency counts, mode |
| Satisfaction rating | Qualitative | Ordinal | Median, mode, Mann-Whitney U |
| Time on site (minutes) | Quantitative (continuous) | Ratio | Mean, std dev, regression |
| Year of purchase | Quantitative | Interval | Time 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.
A hospital records patient data for a research study.
| Variable | Data type | Scale | Appropriate analysis |
|---|---|---|---|
| Blood type | Qualitative | Nominal | Chi-square, disease prevalence by group |
| Pain severity (1–10) | Qualitative / quantitative* | Ordinal (or interval) | Non-parametric tests if ordinal |
| Body temperature (°C) | Quantitative (continuous) | Interval | Parametric tests, t-tests |
| Number of hospital visits | Quantitative (discrete) | Ratio | Regression, Poisson modeling |
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.
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:
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.
Three questions to test whether this stuck.
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.
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.
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).
Measures of Central Tendency: mean, median, and mode in depth, when to use each, and how outliers can deceive you.