Python 按降序打印行值
我有一个数据框,有1000行,底部有一个Python 按降序打印行值,python,pandas,sorting,dataframe,Python,Pandas,Sorting,Dataframe,我有一个数据框,有1000行,底部有一个Total行: 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
Total
行:
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
我想按降序绘制Total
行,甚至根据df.loc['Total']
按降序对数据帧列进行排序
目前我有:
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()
但是,对于Total
,我得到了一个keyrerror
我找到了按列而不是按行排序的资源。将
axis=0
更改为axis=1
,因为您正在排序列,而不是行。将axis=0
更改为axis=1
,因为您正在排序列,而不是行