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

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

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

      1. 计算DataFrame上的百分比

        Calculate percentage on DataFrame(计算DataFrame上的百分比)
            <tbody id='VeSG3'></tbody>

            • <bdo id='VeSG3'></bdo><ul id='VeSG3'></ul>
            • <legend id='VeSG3'><style id='VeSG3'><dir id='VeSG3'><q id='VeSG3'></q></dir></style></legend>

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

              1. <tfoot id='VeSG3'></tfoot>
                  <i id='VeSG3'><tr id='VeSG3'><dt id='VeSG3'><q id='VeSG3'><span id='VeSG3'><b id='VeSG3'><form id='VeSG3'><ins id='VeSG3'></ins><ul id='VeSG3'></ul><sub id='VeSG3'></sub></form><legend id='VeSG3'></legend><bdo id='VeSG3'><pre id='VeSG3'><center id='VeSG3'></center></pre></bdo></b><th id='VeSG3'></th></span></q></dt></tr></i><div id='VeSG3'><tfoot id='VeSG3'></tfoot><dl id='VeSG3'><fieldset id='VeSG3'></fieldset></dl></div>
                • 本文介绍了计算DataFrame上的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试计算以下数据帧的每个犯罪的百分比:

                          Violent     Murder      Larceny_Theft   Vehicle_Theft
                  Year
                  1960    288460      3095700     1855400         328200
                  1961    289390      3198600     1913000         336000
                  1962    301510      3450700     2089600         366800
                  1963    316970      3792500     2297800         408300
                  1964    364220      4200400     2514400         472800
                  
                  所以我应该先计算每年的犯罪总数,然后用它来计算每种犯罪的百分比。我正在尝试以下操作:

                  > perc = (crime *100) / crime.sum(axis=1)
                  

                  有什么想法吗? 谢谢!

                  推荐答案

                  使用函数DataFrame.divFOR除以Series

                  perc = crime.mul(100).div(crime.sum(axis=1), axis=0)
                  #perc = (crime *100).div(crime.sum(axis=1), axis=0)
                  print (perc)
                         Violent     Murder  Larceny_Theft  Vehicle_Theft
                  Year                                                   
                  1960  5.180899  55.600457      33.323994       5.894651
                  1961  5.044283  55.753976      33.345012       5.856730
                  1962  4.856320  55.579268      33.656487       5.907925
                  1963  4.650675  55.644649      33.713981       5.990695
                  1964  4.822943  55.621029      33.295285       6.260742
                  

                  这篇关于计算DataFrame上的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                    <legend id='iycw0'><style id='iycw0'><dir id='iycw0'><q id='iycw0'></q></dir></style></legend>
                  • <i id='iycw0'><tr id='iycw0'><dt id='iycw0'><q id='iycw0'><span id='iycw0'><b id='iycw0'><form id='iycw0'><ins id='iycw0'></ins><ul id='iycw0'></ul><sub id='iycw0'></sub></form><legend id='iycw0'></legend><bdo id='iycw0'><pre id='iycw0'><center id='iycw0'></center></pre></bdo></b><th id='iycw0'></th></span></q></dt></tr></i><div id='iycw0'><tfoot id='iycw0'></tfoot><dl id='iycw0'><fieldset id='iycw0'></fieldset></dl></div>

                      <tbody id='iycw0'></tbody>
                  • <tfoot id='iycw0'></tfoot>

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

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