【问题标题】:Is there any function to retrieve Counters values? [duplicate]是否有任何功能可以检索计数器值? [复制]
【发布时间】:2021-06-21 10:55:47
【问题描述】:

这就是我所拥有的:

In:  u = np.random.choice(['Male','Female'], len(null_Gender), p = P_Gender)
In:  Counter(u)
Out: Counter({'Female': 115730, 'Male': 357627})

我想提取计数值,而不是手动编写它们。

【问题讨论】:

  • 删除pandas标签,因为它在这里无关紧要。

标签: python python-3.x


【解决方案1】:

collections.Counterdict 的子类,所以你可以直接调用values

from collections import Counter

c = Counter({'Female': 115730, 'Male': 357627})
print(list(c.values()))
>>> [357627, 115730]

【讨论】:

  • 好的!谢谢。它有效
猜你喜欢
  • 1970-01-01
  • 2011-12-26
  • 1970-01-01
  • 2019-11-03
  • 1970-01-01
  • 2021-12-25
  • 2016-09-24
  • 1970-01-01
  • 2020-05-10
相关资源
最近更新 更多