TypeError when finding mode for each Outlet_Type



When I run this code from the tutorial:

#Import mode function:
from scipy.stats import mode

#Determing the mode for each
outlet_size_mode = data.pivot_table(values='Outlet_Size', columns='Outlet_Type',aggfunc=(lambda x:mode(x).mode[0]))
print ('Mode for each Outlet_Type:')
print (outlet_size_mode)

I get

TypeError: '<' not supported between instances of 'str' and 'float'

I know the error occurs because Outlet_Size has missing values but I’m not sure how to correct it.


Hi @warrior,

  1. You can (temporarily) remove the rows with missing values and then find out the mode value, derive other inferences etc.
  2. Simply impute the missing values in outlet size first, then check the mode value for outlet type.


I am getting the same error. Cn share the exact stepsto be followed