pythonpandasdataframe

Pandas get the most frequent values of a column


i have this dataframe:

0 name data
1 alex asd
2 helen sdd
3 alex dss
4 helen sdsd
5 john sdadd

so i am trying to get the most frequent value or values(in this case its values) so what i do is:

dataframe['name'].value_counts().idxmax()

but it returns only the value: Alex even if it Helen appears two times as well.


Solution

  • By using mode

    df.name.mode()
    Out[712]: 
    0     alex
    1    helen
    dtype: object