Multimode function shows only one result

77 Views Asked by At
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))

This gives me this result:

[(9, 93), (10, 90), (8, 89), (13, 83), (11, 83), (5, 80)]
The multimode of list is :  [9]
The mode of list is :  9

Why can't I get a Multimode list? If you see only shows one result for Multimode.

1

There are 1 best solutions below

3
Claudio On

This is right. Multimode shows only one result, because there is only one result to show.

The code below:

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))

prints:

[(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

And as you can see from the printout of Counter there are three most frequent values, so the multimode gives a list with three elements.

In case of your data there are no other items occurring the same number of times as the most frequent one, so there is only one value in the list.

      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)]