How-to: give a specific sorting order to categorical values

In pandas, you can give a specific sorting order to categorical values by creating a categorical variable with an ordered category. Here’s an example: In this example: This can be useful when you want to ensure that certain operations, such as sorting or plotting, take into account the natural order of the days of the…