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’?

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

Leave a Reply