Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading