Data Types

Learn how Altair encodes data types.

We'll cover the following

Every single datum is associated with a data type that specifies the type of value that a datum can hold. Different data types allow for different operations we can perform on the data, and they also determine the type and amount of storage that is allocated for the data. Data types are important because they ensure data is stored and processed correctly in a program.

Data types in Altair

Altair supports the following data types:

  • Nominal: This is data that can be divided into distinct categories, but the categories do not have an inherent order. For example, we use this data type to represent the names of different fruits in a dataset.

  • Ordinal: This is data that can be divided into distinct categories with an inherent order. For example, we use this data type to represent the days of the week, where the order of the days is essential.

  • Quantitative: These are numerical and continuous data. For example, we use this data type to represent sales data.

  • Temporal: This is data with a temporal (i.e., date or time) component. For example, we use this data type to represent the date on which a sale occurred.

  • GeoJSON: This is data with a geographic component, such as latitude and longitude coordinates. We use this data type to create maps.

When we build a chart in Altair, we have to associate each column involved in the chart with a data type. Altair sets a default type for each column. However, in some cases, Altair’s choice is incorrect, and we must correct it manually.

We specify a data type for some encoding channels, such as x, y, and color using one of the following options:

  • We use a shorthand code following the : symbol, after the column name, such as :Q for quantitive data types.

  • We use the input parameter type.

Get hands-on with 1200+ tech skills courses.