小编Ran*_*awa的帖子

Pandas,获取Dataframe列中单个值的计数

使用pandas,我想得到列中特定值的计数.我知道使用df.somecolumn.ravel()会给我所有唯一值及其计数.但是如何计算某些特定值.

In[5]:df
Out[5]:
        col 
         1
         1
         1
         1
         2
         2
         2
         1
Run Code Online (Sandbox Code Playgroud)

期望:

  To get count of 1.

  In[6]:df.somecalulation(1)
  Out[6]: 5

  To get count of 2.

  In[6]:df.somecalulation(2)
  Out[6]: 3
Run Code Online (Sandbox Code Playgroud)

python pandas

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

pandas ×1

python ×1