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

most common value in column CSV file using python

I am beginner in python and
I need to get the most common value of that column using code

I have next table from csv file:

elements value
1 y
2 y
3 y
4 n
5 n

How I can get most common (common means that the count of y is 3, count of n is 2 , so common is y) ‘value’?

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

>Solution :

You can use count_values() and extract it from the result

df.value.value_counts(sort=True).index[0]
# 'y'

Just be careful what should happen if there are multiple ‘most common’ values.

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