Skip to content
Tutorials Center
My learning

Topics

Lesson 2 of 37 ยท Getting Started

Types of Data

Learn the difference between categorical and numerical data, and between discrete and continuous variables, with examples and a Python classifier.

Before you can display or average data, you must know what kind of data you have. A pie chart makes sense for favorite colors but not for exact heights, and you can find the mean of shoe sizes but not of eye colors. This lesson gives you a simple map of data types.

A variable is any characteristic that can take different values from one person or object to the next: height, eye color, number of siblings. Each recorded value is an observation.

Categorical and numerical data

The first split is between words and numbers.

  • Categorical (qualitative) data put things into groups or categories: eye color, favorite sport, type of pet.
  • Numerical (quantitative) data are measured or counted amounts: height, number of goals, temperature.
flowchart TD
  D["Data"] --> C["Categorical"]
  D --> N["Numerical"]
  C --> C1["Nominal: no order<br/>(eye color)"]
  C --> C2["Ordinal: ordered<br/>(small, medium, large)"]
  N --> N1["Discrete: counted<br/>(siblings)"]
  N --> N2["Continuous: measured<br/>(height)"]

A family tree of data types.

Nominal and ordinal

Categorical data come in two flavors.

  • Nominal: the categories have no natural order. Examples: blood type, country, favorite fruit.
  • Ordinal: the categories have a meaningful order, but the gaps between them are not measured. Examples: "poor, fair, good, excellent", or finishing positions 1st, 2nd, 3rd.

A trap: a bus route number such as 42 looks numerical, but it is just a label. Adding two route numbers means nothing, so it is nominal.

Discrete and continuous

Numerical data also come in two kinds.

  • Discrete data can only take separate values, usually whole numbers that you count. The number of students in a class can be 28 or 29, never 28.5. Shoe sizes in whole and half steps are also discrete because only certain values exist.
  • Continuous data can take any value in a range, usually from measuring. A height might be 162 cm, 162.4 cm or 162.4137 cm; only the precision of your ruler limits it.

A useful test: "Could there be a value between two neighbors?" Between 3 children and 4 children, there is nothing. Between 162 cm and 163 cm, there are infinitely many heights.

Continuous data are always rounded when recorded. A height written as 162 cm usually means "between 161.5 cm and 162.5 cm". The quantity is still continuous even though the recording is rounded.

Variable Type Reason
Favorite subject Categorical, nominal Names, no order
Customer rating (1 to 5 stars) Categorical, ordinal (often treated as numerical) Ordered, gaps not exact
Goals scored in a match Numerical, discrete Counted
Time to run 100 m Numerical, continuous Measured
Mass of an apple Numerical, continuous Measured
Number of pets Numerical, discrete Counted
Python Classify values automatically (a simple rule of thumb)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Notice the limits of the rule: a column of whole-number heights in centimeters would be flagged "discrete" although height is continuous. The meaning of the variable matters more than how it is typed into a computer.

Why the type matters

The type of data decides which tools are sensible.

Type Sensible displays Sensible summaries
Nominal Bar chart, pie chart Mode, counts, percentages
Ordinal Bar chart Mode, median
Discrete numerical Bar chart, dot plot Mean, median, mode, range
Continuous numerical Histogram, box plot Mean, median, standard deviation
Python Which summary fits which data?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

You cannot calculate a mean of colors. Sizes can be put in order, so a median makes sense, but a mean of "S, M, L" would not.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which variable is continuous?

    Mass is measured and can take any value in a range. The other two are counted whole numbers.
  2. 2. Finishing positions 1st, 2nd and 3rd in a race are best described as

    The positions have a meaningful order, but the gaps between them (time differences) are not given by the labels.
  3. 3. A shop records customers' favorite flavor of ice cream. This is

    Flavors are names with no natural order.
  4. 4. A bus route is numbered 42. What type of data is the route number?

    Route numbers identify routes. Their arithmetic has no meaning, so they behave like names.

Summary

  • Categorical data are groups (nominal: no order; ordinal: ordered). Numerical data are counts or measurements.
  • Discrete data are counted in separate values; continuous data are measured and can take any value in a range.
  • Numbers used as labels (route numbers, phone numbers) are not truly numerical.
  • The data type decides which charts and averages make sense.

Next: Populations and Samples