<tfoot id='djZJf'></tfoot>
  1. <small id='djZJf'></small><noframes id='djZJf'>

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

    1. <legend id='djZJf'><style id='djZJf'><dir id='djZJf'><q id='djZJf'></q></dir></style></legend>

      我如何 pandas 分组获得总和?

      How do I Pandas group-by to get sum?(我如何 pandas 分组获得总和?)
          <tbody id='XPDQj'></tbody>
        <legend id='XPDQj'><style id='XPDQj'><dir id='XPDQj'><q id='XPDQj'></q></dir></style></legend>
        <tfoot id='XPDQj'></tfoot>
          <bdo id='XPDQj'></bdo><ul id='XPDQj'></ul>

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

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

              • 本文介绍了我如何 pandas 分组获得总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用这个数据框:

                I am using this data frame:

                Fruit   Date      Name  Number
                Apples  10/6/2016 Bob    7
                Apples  10/6/2016 Bob    8
                Apples  10/6/2016 Mike   9
                Apples  10/7/2016 Steve 10
                Apples  10/7/2016 Bob    1
                Oranges 10/7/2016 Bob    2
                Oranges 10/6/2016 Tom   15
                Oranges 10/6/2016 Mike  57
                Oranges 10/6/2016 Bob   65
                Oranges 10/7/2016 Tony   1
                Grapes  10/7/2016 Bob    1
                Grapes  10/7/2016 Tom   87
                Grapes  10/7/2016 Bob   22
                Grapes  10/7/2016 Bob   12
                Grapes  10/7/2016 Tony  15
                

                我想按 Name 然后按水果来汇总,以获得每个 NameFruit 总数.例如:

                I want to aggregate this by Name and then by fruit to get a total number of Fruit per Name. For example:

                Bob,Apples,16
                

                我尝试按 NameFruit 进行分组,但如何获得 Fruit 的总数?

                I tried grouping by Name and Fruit but how do I get the total number of Fruit?

                推荐答案

                使用 GroupBy.sum:

                df.groupby(['Fruit','Name']).sum()
                
                Out[31]: 
                               Number
                Fruit   Name         
                Apples  Bob        16
                        Mike        9
                        Steve      10
                Grapes  Bob        35
                        Tom        87
                        Tony       15
                Oranges Bob        67
                        Mike       57
                        Tom        15
                        Tony        1
                

                这篇关于我如何 pandas 分组获得总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Split a Pandas column of lists into multiple columns(将 Pandas 的列表列拆分为多列)
                How does the @property decorator work in Python?(@property 装饰器在 Python 中是如何工作的?)
                What is the difference between old style and new style classes in Python?(Python中的旧样式类和新样式类有什么区别?)
                How to break out of multiple loops?(如何打破多个循环?)
                How to put the legend out of the plot(如何将传说从情节中剔除)
                Why is the output of my function printing out quot;Nonequot;?(为什么我的函数输出打印出“无?)
                <tfoot id='cnpnB'></tfoot>

                    1. <legend id='cnpnB'><style id='cnpnB'><dir id='cnpnB'><q id='cnpnB'></q></dir></style></legend>
                        <tbody id='cnpnB'></tbody>

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

                        • <bdo id='cnpnB'></bdo><ul id='cnpnB'></ul>

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