• <tfoot id='Oh63x'></tfoot>

    1. <i id='Oh63x'><tr id='Oh63x'><dt id='Oh63x'><q id='Oh63x'><span id='Oh63x'><b id='Oh63x'><form id='Oh63x'><ins id='Oh63x'></ins><ul id='Oh63x'></ul><sub id='Oh63x'></sub></form><legend id='Oh63x'></legend><bdo id='Oh63x'><pre id='Oh63x'><center id='Oh63x'></center></pre></bdo></b><th id='Oh63x'></th></span></q></dt></tr></i><div id='Oh63x'><tfoot id='Oh63x'></tfoot><dl id='Oh63x'><fieldset id='Oh63x'></fieldset></dl></div>

      <small id='Oh63x'></small><noframes id='Oh63x'>

        <bdo id='Oh63x'></bdo><ul id='Oh63x'></ul>
        <legend id='Oh63x'><style id='Oh63x'><dir id='Oh63x'><q id='Oh63x'></q></dir></style></legend>
      1. 绘制 Pandas 多索引条形图

        Plotting Pandas Multiindex Bar Chart(绘制 Pandas 多索引条形图)

        <tfoot id='uP472'></tfoot>

            <legend id='uP472'><style id='uP472'><dir id='uP472'><q id='uP472'></q></dir></style></legend>
          • <i id='uP472'><tr id='uP472'><dt id='uP472'><q id='uP472'><span id='uP472'><b id='uP472'><form id='uP472'><ins id='uP472'></ins><ul id='uP472'></ul><sub id='uP472'></sub></form><legend id='uP472'></legend><bdo id='uP472'><pre id='uP472'><center id='uP472'></center></pre></bdo></b><th id='uP472'></th></span></q></dt></tr></i><div id='uP472'><tfoot id='uP472'></tfoot><dl id='uP472'><fieldset id='uP472'></fieldset></dl></div>
              <bdo id='uP472'></bdo><ul id='uP472'></ul>
                <tbody id='uP472'></tbody>

                • <small id='uP472'></small><noframes id='uP472'>

                • 本文介绍了绘制 Pandas 多索引条形图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何将 Python Pandas 多索引数据框绘制为带有组标签的条形图?是否有任何绘图库直接支持这一点?这个

                  如果您不想堆叠条形图:

                  data.unstack().plot(kind='bar')

                  How can I plot a Python Pandas multiindex dataframe as a bar chart with group labels? Do any of the plotting libraries directly support this? This SO post shows a custom solution using matplotlib, but is there direct support for it?

                  As an example:

                  quarter  company
                  Q1       Blue       100
                           Green      300
                  Q2       Blue       200
                           Green      350
                  Q3       Blue       300
                           Green      400
                  Q4       Blue       400
                           Green      450
                  Name: count, dtype: int64
                  

                  ...can this dataframe be plotted with group labels like this?

                  Thanks in advance,

                  Rafi

                  解决方案

                  import pandas as pd
                  
                  data = pd.DataFrame([
                          ('Q1','Blue',100),
                          ('Q1','Green',300),
                          ('Q2','Blue',200),
                          ('Q2','Green',350),
                          ('Q3','Blue',300),
                          ('Q3','Green',400),
                          ('Q4','Blue',400),
                          ('Q4','Green',450),
                      ], 
                      columns=['quarter', 'company', 'value']
                  )
                  data = data.set_index(['quarter', 'company']).value
                  
                  data.unstack().plot(kind='bar', stacked=True)
                  

                  If you don't want to stack your bar chart:

                  data.unstack().plot(kind='bar')
                  

                  这篇关于绘制 Pandas 多索引条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                • <i id='Pkxcl'><tr id='Pkxcl'><dt id='Pkxcl'><q id='Pkxcl'><span id='Pkxcl'><b id='Pkxcl'><form id='Pkxcl'><ins id='Pkxcl'></ins><ul id='Pkxcl'></ul><sub id='Pkxcl'></sub></form><legend id='Pkxcl'></legend><bdo id='Pkxcl'><pre id='Pkxcl'><center id='Pkxcl'></center></pre></bdo></b><th id='Pkxcl'></th></span></q></dt></tr></i><div id='Pkxcl'><tfoot id='Pkxcl'></tfoot><dl id='Pkxcl'><fieldset id='Pkxcl'></fieldset></dl></div>
                  <legend id='Pkxcl'><style id='Pkxcl'><dir id='Pkxcl'><q id='Pkxcl'></q></dir></style></legend>
                      <tfoot id='Pkxcl'></tfoot>

                            <bdo id='Pkxcl'></bdo><ul id='Pkxcl'></ul>

                            <small id='Pkxcl'></small><noframes id='Pkxcl'>

                              <tbody id='Pkxcl'></tbody>