首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多模函数只显示一个结果

多模函数只显示一个结果
EN

Stack Overflow用户
提问于 2022-09-25 18:00:05
回答 1查看 29关注 0票数 -1
代码语言:javascript
复制
from numpy import genfromtxt
Birds = genfromtxt('DataLot.csv', dtype=int, delimiter=',')
import statistics
from collections import Counter
columnaA = Birds[:,1]
print(Counter(columnaA).most_common(6))
print("The multimode of list is : ", statistics.multimode(columnaA))
print("The mode of list is : ", statistics.mode(columnaA))

这给了我这个结果:

代码语言:javascript
复制
[(9, 93), (10, 90), (8, 89), (13, 83), (11, 83), (5, 80)]
The multimode of list is :  [9]
The mode of list is :  9

为什么我不能得到一个多模列表?如果您只看到一个多模的结果。

EN

回答 1

Stack Overflow用户

发布于 2022-09-25 18:14:19

这是正确的。多模只显示一个结果,因为只有一个结果要显示。

守则如下:

代码语言:javascript
复制
import statistics
from collections import Counter
columnaA = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,6,7,7,8,8,9,9]
print(Counter(columnaA).most_common(6))
print("The multimode of list is : ", statistics.multimode(columnaA))
print("The mode of list is      : ", statistics.mode(columnaA))

指纹:

代码语言:javascript
复制
[(1, 4), (2, 4), (3, 4), (4, 3), (5, 2), (6, 2)]
The multimode of list is :  [1, 2, 3]
The mode of list is      :  1

从计数器的打印输出中可以看到,有三个最常见的值--,所以多模给出了一个包含三个元素的列表。

如果您的数据中没有其他项发生与最频繁项相同的次数,所以列表中只有一个值。

代码语言:javascript
复制
      v-- there is only one item with count 93 and this is the [9]
[(9, 93), (10, 90), (8, 89), (13, 83), (11, 83), (5, 80)]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73846715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档