[英]Bar chart from Pandas Dataframe
I would like to create a Bar chart from a pandas df我想从熊猫 df 创建条形图
The source file is an excel file with column headers: 'Jan', 'Feb','Mar'...源文件是一个带有列标题的 excel 文件:'Jan'、'Feb'、'Mar'...
The rows contain just values行只包含值
When I created the df in pandas I then transposed the df and used df.plot()当我在 Pandas 中创建 df 时,我转置了 df 并使用了 df.plot()
However, I could not get any axis labels.但是,我无法获得任何轴标签。
Any advice would be good任何建议都会很好
df1=read_excel(‘filename’)
df1 = df1.T
df1 = df1.sum(axis=‘columns’)
df1.plot()
The output should be a column name followed by the sum of all corresponding values in each column including a visual Bar chart.输出应该是一个列名,后跟每列中所有相应值的总和,包括一个可视条形图。
Thanks a lot!非常感谢!
I tried to reproduce the case, but it works with me using the following code :我试图重现这个案例,但它使用以下代码对我有用:
data5.txt :数据5.txt:
Jan Feb Mar
1 2 3
4 5 6
Then :然后 :
df1 = pd.read_csv('data/data5.txt', sep='\t')
df1 = df1.T
df1 = df1.sum(axis="columns")
ax = df1.plot(kind='bar')
ax.set_xlabel("Months")
ax.set_ylabel("Values")
ax.set_title("Title")
Result :结果 :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.