pandas.Categorical: Turn a List of Strings into a Categorical Variable

pandas.Categorical: Turn a List of Strings into a Categorical Variable

If you want to create a categorical variable, use pandas.Categorical. This variable takes on a limited number of possible values and can be ordered.

In the code above, I use pd.Categorical to create a list of ordered categories. This list can be sorted based on its specified order.

Link to previous tips on pandas.

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran