[英]Pandas DataFrame bar plot with sort_values by other column
I have a Pandas DataFrame. 我有一个Pandas DataFrame。 I want to plot two columns' values with bar plot, and the bar plot sorts values by the other column.
我想用条形图绘制两列的值,条形图按另一列对值进行排序。
For example, I want to sort values in descending order by column a_b
(sum of column a
and b
). 例如,我想按列
a_b
(列a
和b
总和)按降序对值进行排序。 In addition, the xlabel is rotated, I want to fix it. 另外,xlabel旋转,我想修复它。
Your help would be appreciated. 非常感谢您的帮助。
import pandas as pd
%matplotlib inline
a = pd.Series([4,8,6,7,8,3,9,7])
b = pd.Series([3,6,8,3,4,6,10,4])
a_b = a+b
df = pd.concat([a,b,a_b],axis=1,join='inner')
df.columns = ['a','b','c']
df[['a','b']].sort_values(by='a',ascending=False).plot(kind='bar',stacked=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.