簡體   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