category type

The category type stores a column with a limited number of distinct values as integer codes and a table of categories. It reduces memory, speeds up some operations and allows a logical order (ordered=True). It suits variables such as country, status or size.

Example

df['statut'] = df['statut'].astype('category')

Related concepts

The whole glossary