O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Categoricals

A pandas Categorical is used to represent a categorical variable. A categorical variable consists of a finite set of values and is often used to map values into a set of categories and track how many values are present in each category. Another purpose is to map sections of continuous values into a discrete set of named labels, an example of which is mapping a numeric grade to a letter grade. We will examine how to perform this mapping at the end of the chapter.

There are several ways to create a pandas Categorical. The following screenshot demonstrates creating a Categorical directly from a list:

This Categorical is ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required