Cover image
Cover image
(source)

When working with pandas dataframes, sometimes there is a need to sort data in a column by a specific order. For example, you may want to sort a Dataframe by its column of months so that they are properly sorted for a time series visualization. The problem is, a normal sort will get your months sorted alphabetically, not in the natural January to December order.

It’s in cases like these that the Categorical function can help. Just like you can transform a column to a numeric type, you can also transform it to the category type to be treated as a proper categorical column. More than being treated as a column of categorical data, at the moment of casting you can specify a list or an array containing the unique categories (i.e., …

About

José Fernando Costa

I write technical articles about data analysis and other things that catch my attention

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store