# Specify the logical order of the weather ratings cats = pd.CategoricalDtype(['good', 'bad', 'worse'], ordered=True) # Change the data type of 'rating' to category df['column'] = df.column.astype(cats)
df = df['col_name'].astype('category')