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

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

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

      1. <tfoot id='UZS2L'></tfoot>

        pandas DataFrame 列中值的计数频率

        Count frequency of values in pandas DataFrame column(pandas DataFrame 列中值的计数频率)

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

              • <legend id='vhFCY'><style id='vhFCY'><dir id='vhFCY'><q id='vhFCY'></q></dir></style></legend>
              • <tfoot id='vhFCY'></tfoot>
                  <tbody id='vhFCY'></tbody>

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

                  本文介绍了pandas DataFrame 列中值的计数频率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想计算每个值在数据框中出现的次数.

                  I want to count number of times each values is appearing in dataframe.

                  这是我的数据框 - df:

                  Here is my dataframe - df:

                      status
                  1     N
                  2     N
                  3     C
                  4     N
                  5     S
                  6     N
                  7     N
                  8     S
                  9     N
                  10    N
                  11    N
                  12    S
                  13    N
                  14    C
                  15    N
                  16    N
                  17    N
                  18    N
                  19    S
                  20    N
                  

                  我想要计数字典:

                  例如.counts = {N: 14, C:2, S:4}

                  我试过 df['status']['N'] 但它给出了 keyErrordf['status'].value_counts 但没有用.

                  I have tried df['status']['N'] but it gives keyError and also df['status'].value_counts but no use.

                  推荐答案

                  你可以使用value_countsto_dict:

                  print df['status'].value_counts()
                  N    14
                  S     4
                  C     2
                  Name: status, dtype: int64
                  
                  counts = df['status'].value_counts().to_dict()
                  print counts
                  {'S': 4, 'C': 2, 'N': 14}
                  

                  这篇关于pandas DataFrame 列中值的计数频率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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;?(为什么我的函数输出打印出“无?)

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

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

                            <tbody id='awpBF'></tbody>
                        1. <tfoot id='awpBF'></tfoot>

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