繁体   English   中英

Pandas dataframe 多列条 plot

[英]Pandas dataframe multiple columns bar plot

我正在尝试在 dataframe 中创建一个包含多列的条形图。 我的 dataframe 看起来像这样。

Age      Index 1     Index 2     Index 3     Index 4
18-30    20.000000  0.000000    0.000000    5.000000    
31-40    27.807487  6.746195    2.694364    1.069519    
41-50    45.499022  6.849315    1.663405    3.228963    
51-60    41.176471  0.000000    0.000000    11.764706

所需 output 图表

Age列创建索引(如有必要),然后rename列并最后使用DataFrame.plot.bar

d = {'Index 1':'Payment', 'Index 2':'Gender Focus', 
     'Index 3':'H&S General', 'Index 4': 'H&S Covid 19'}
df.set_index('Age').rename(columns=d).plot.bar()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM