Search code examples
statisticsmode

What is the meaning of mode(x).mode[0]?


I am trying to find mode along a column(named Outlet_Size) of a dataset using pandas library of python which contains values in the form of {small, medium,large} corresponding to 10 different outlet stores with total of 1000+ rows.enter image description here. For Finding the mode along that column for each store type the following code was used:

Determing the mode for each type of outlet(10 different types)

outlet_size_mode = data.pivot_table(values='Outlet_Size', columns='Outlet_Type',aggfunc=(lambda x:mode(x).mode[0]) ) .

However I am unable to understand the format of using the lambda function mode(x).mode[0]. What is the meaning of that?


Solution

  • For a column having several rows mode(x) can be an array as there can be multiple values with high frequency. We will take the first one by default always using: mode[0] at the end.