Methods for modifying categorical data

Once we have our DataFrame columns correctly encoded with dtype=category, there are numerous methods that we can apply to them. We’ll explore some common methods with the example of the Education column from the credit card dataset.

Note: When dealing with Series objects, which include DataFrame columns, we include a cat. prefix in front of the methods for them to work e.g., cat.add_categories(). It’s a way for us to access the methods that come with the .cat attribute of Series objects.

View category properties

Besides printing out the entire column to view the output, another way to check the categorical properties of the Education column is with the attributes categories and ordered, as shown below:

Get hands-on with 1200+ tech skills courses.