Reputation: 406
I've got a dataframe with 1000 rows and a Total
row at the bottom:
df.tail()
22 88 24 11 12 21 99 61 13 44 65 64 62 89 220 63
996 1 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0
997 1 1 0 3 0 0 0 0 0 0 0 0 0 0 0 0
998 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
999 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
Total 289 601 304 360 115 31 54 14 33 13 10 14 11 2 13 8
I'd like to plot the Total
row in descending order, or even sort the dataframe columns in descending order based on df.loc['Total']
.
Currently I've got:
df_sorted = df.sort_values(by=['Total'], axis=0, ascendin=False)
sorted_plot = df_sorted.loc['Total'].plot(kind='bar', title ="Codes", figsize=(15, 10), legend=True, fontsize=12)
plt.show()
However, I'm getting a KeyError for Total
.
I've found resources to sort by columns but not by a row.
Upvotes: 0
Views: 809