Python Pandas: How to sort group bar chart?

I have the following code that is currently displaying the group bar chart.

pd.crosstab(train_data['workclass'],train_data['income']).plot(kind="bar")
plt.xlabel('Workclass')
plt.ylabel('Income Count')
plt.suptitle("Training Data: Workclass vs Income", fontweight="bold")

The current chart looks like this:

enter image description here

I want to display the chart by sorting the orange section (income >50K) in descending order. So the tallest orange bar should be on the left side. How do I do that?



Read more here: https://stackoverflow.com/questions/67016896/python-pandas-how-to-sort-group-bar-chart

Content Attribution

This content was originally published by hongkongbboy at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: