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.
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.
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:
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 data | Quantitative data | |
|---|---|---|
| Nature | Categories, descriptions | Numbers that measure or count |
| Answers | "What type?" or "Which category?" | "How many?" or "How much?" |
| Examples | Gender, cuisine type, blood group | Age, income, temperature |
| Key operations | Frequency counts, mode, and the median if the categories have an order | Mean, variance, regression |
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).
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.
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:
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.
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:
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:
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.
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:
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.
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.
- File size. 0 bytes means no data, and 100 MB really is ten times 10 MB.
- Elapsed time. 0 seconds means no time has passed, and 20 seconds is twice 10 seconds.
- Counts, like database transactions or webpage clicks. 5,000 clicks is five times 1,000 clicks.
- Income. $0 means no income, and $100,000 is twice $50,000.
- Height, weight, distance, speed, and temperature in kelvin.
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.
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
| Scale | Order | Equal gaps | True zero | Middle value you can use | Example |
|---|---|---|---|---|---|
| Nominal | No | No | No | Mode | Blood type, zip code |
| Ordinal | Yes | No | No | Median, mode | Satisfaction rating, Mohs hardness |
| Interval | Yes | Yes | No | Mean, median, mode | Temperature in °C, calendar year |
| Ratio | Yes | Yes | Yes | All of them, plus ratios | Income, 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.
| 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, standard deviation, regression |
| Year of purchase | Quantitative | Interval | Trends 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.
| Variable | Data type | Scale | Appropriate analysis |
|---|---|---|---|
| Blood type | Qualitative | Nominal | Chi-square test, rates by group |
| Pain score (0 to 10) | Debated (see below) | Ordinal, often treated as interval | Rank-based tests if treated as ordinal |
| Body temperature (°C) | Quantitative (continuous) | Interval | Mean, t-tests |
| Number of hospital visits | Quantitative (discrete) | Ratio | Regression, Poisson modelling |
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:
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:
- Is this qualitative or quantitative?
- If quantitative, is it discrete or continuous?
- 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.
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.