liveBook · Manning

Categorical data

As explained in The Well-Grounded Data Analyst

Categorical data consists of values representing membership in discrete, named groups or categories.

Categorical data records membership in a limited set of named groups rather than a measured quantity. Typical fields include customer location, department, demographics, survey responses, colors, and political parties. A numeric-looking field can still be categorical when its codes stand for groups rather than amounts. section 6.0 section 6.1

Classify categories as nominal when they have no natural order, such as colors, or ordinal when they have an order without meaningful equal spacing, such as sizes or agreement responses. Do not apply continuous-data reasoning—such as averages, correlations, or unit-change interpretations—to arbitrary category codes. section 6.1 section 6.1.1

Work with categorical values by first checking how they are represented, then choosing transformations and comparisons that preserve their meaning:

  • Inspect distinct values, missingness, and whether multiple-choice answers are stored together as semicolon-separated strings. section 6.4.1
  • Set an explicit order for ordinal categories when ordering affects sorting, display, or analysis. section 5.4.3 section 7.3.1
  • Create mutually exclusive binary indicator columns through one-hot encoding when a model requires numeric inputs. section 6.1.1
  • Cross-tabulate categorical variables with pivot tables and heatmaps; reshape wide data or split multiple answers when needed. section 7.3.1
  • Combine similar categories, bin a continuous value into broader groups when useful, and select statistical tests and visualizations that fit the data types. section 7.3.1 section 7.4

Ordering cinema periods

Monthly admissions can be labeled pre-COVID, during COVID, and post-lockdowns. Treating those labels as an ordered categorical field keeps plots and grouped summaries in chronological order rather than alphabetical order, while a count including missing values checks that every row was assigned. section 5.4.3

Table 6.1 An overview of the different types of data
Name
Categorical or continuous?
Properties
Example
Nominal
Categorical
Data has discrete values, and categories are not ordered.
Colors, political parties
Ordinal
Categorical
Data has discrete values, and categories have a natural order, but spacing is uneven between categories.
T-shirt sizes (S/M/L), survey responses (good versus bad)
Interval
Continuous
Values are spaced evenly, but zero is not an absence of the measurement.
Temperature
Ratio
Continuous
Values are spaced evenly, and zero means an absence of the measurement.
Height, weight

Compare nominal and ordinal categories with interval and ratio measurements before choosing summaries, visualizations, or models. section 6.1

How The Well-Grounded Data Analyst covers it

How deep it goes
Defines nominal and ordinal categories, then develops inspection, encoding, cross-tabulation, binning, visualization, and statistical-test choices without deriving the tests.
Examples
Uses heart-disease slope codes, cinema COVID periods and genres, and a developer survey about AI tools.
What it assumes
Builds from recognizing discrete groups versus continuous measures and assumes enough data familiarity to inspect columns and missing values.
What you can do after
Apply it by inspecting categories, preserving ordinal order, encoding model inputs, and comparing groups with appropriate tables, plots, and tests.
How it connects
Connects to one-hot encoding, regression, missing data, pivot tables, heatmaps, wide and long data, binning, and statistical tests.

Also explained in

Compare how 16 books explain categorical data →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Data Analyst. The section links point to the parts of the book it draws on.