0

I have a dataframe that is using the following classification:

First column: 'high', 'low', 'med', 'vhigh' (very high)

Second column: 'acc': acceptable, 'unacc': unacceptable, 'good' and 'vgood'

But when I plot it, the graph is not the most intuitive one:

https://i.stack.imgur.com/njW8q.png

When I am using groupby, it's sorting alphabetically. I'd like to see it in an order like: 'unacc', 'acc', 'good', 'vgood'

How could I change the dataframe to use this order?

df_buy_class = df.groupby(['buying', 'classification']).count().reset_index()
df_buy_class.rename(columns={'maint': 'number of cars'}, inplace=True)

fig = plt.figure(figsize=(40,5))
sns.catplot(x='classification', y='number of cars', hue='buying', kind="bar", data = df_buy_class)
plt.show()
  • 2
    To set an order by making the column categorical: `df['buying'] = pd.Categorical(df['buying'], ['low', 'med', 'high', 'vhigh'])` – JohanC Mar 17 '22 at 22:11

0 Answers0