• <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 多索引条形图

        时间:2023-09-29

        <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 多索引条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 Jupyter notebook 或 JupyterLab 中使用破折号? 下一篇:分布式1.21.8需要msgpack,没有安装

                  相关文章

                • <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'>