Home > Enterprise >  Retrieve elements with max occurences with a DRAW(tie) in the max occurrence
Retrieve elements with max occurences with a DRAW(tie) in the max occurrence

Time:11-21

Eg., I have the following list [s, d, s, e, d, d, s]

I need to print the elements with highest occurrences. example output: d 2 s 2

enter image description here

So far, i have been able to get only one element with highest occurrence. Please help me deal with the tie or draw in the max occurrence.

CodePudding user response:

You could do something like this:

counts = df[0].value_counts()
counts = counts[counts == counts.max()]

Output:

>>> counts
s    3
d    3
Name: 0, dtype: int64

>>> counts['s']
3

>>> counts['d']
3
  • Related