liveBook · Manning

Nominal data

As explained in Data Storytelling with Altair and AI

Nominal data contains categorical labels whose values have no intrinsic ordering.

Nominal data consists of distinct categorical labels with no intrinsic order. In Altair, declare a nominal column when mapping categories to visual channels such as position, color, or shape. section 2.1.3 section 3.2.1

Choose the nominal type when the labels identify groups rather than quantities or ranked values:

  • Use `Name:N` for categorical labels on an axis, as in a bar chart with age on x and names on y. section 2.1.3
  • Use `Country:N` to separate lines by country through color; the labels identify series but do not imply a ranking. section 2.3.1
  • Keep nominal data distinct from ordinal data, which has an inherent order, and quantitative data, which represents numerical values. section 3.2.1

Encoding a nominal column in Altair

A DataFrame can contain names, ages, and cities. Encode age quantitatively and names nominally: `chart = alt.Chart(df).mark_bar().encode(x='Age:Q', y='Name:N')`. The `:N` shorthand tells Altair to treat `Name` as an unordered category. section 2.1.3

Listing 2.3 Encodings in Altair
import pandas as pd
import altair as alt

data = {'Name': ['Alice', 'Bob', 'Charlie'],
        'Age': [25, 30, 35],
        'City': ['New York', 'Paris', 'London']
}                                   #1

df = pd.DataFrame(data)      #2

# Create the chart
chart = alt.Chart(df).mark_bar(
).encode(
    x = 'Age:Q',     
    y = 'Name:N' 
)

chart.save('bar-chart.html')

Inspect the complete DataFrame and Altair encoding example, including nominal names and chart export. section 2.1.3

How Data Storytelling with Altair and AI covers it

How deep it goes
Defines nominal data and demonstrates shorthand encoding, but stops short of deeper categorical-data theory.
Examples
Uses names, cities, countries, grouped tourist-arrival lines, and the `Name:N` and `Country:N` shorthand forms.
What you can do after
Build charts that correctly encode unordered categorical columns with Altair’s `:N` shorthand or explicit type property.
How it connects
Connects nominal data with encodings, channels, ordinal data, quantitative data, temporal data, and marks.

Also explained in

Compare how 4 books explain nominal data →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Storytelling with Altair and AI. The section links point to the parts of the book it draws on.