Error encountered while executing Mode calculation in Big Mart Sales prediction problem

Hi I am facing associated problem - getting following error wen calculating the mode of outlet size against Outlet type. I am following

Approach and Solution to break in Top 20 of Big Mart Sales prediction - hosted on AV portal.

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

Error:
TypeError: ‘<’ not supported between instances of ‘str’ and ‘float’

Error is happening in uniqueID module of ‘Mode’

I noticed that this problem is encountering due to presence of NaN in Outlet_size col. now if i replace NaN with sm other value, then it changes the ‘mode’ calculations , specially for Outlet_Type - Grocery.
Please help.

Replace NaN with a random number, say 999. It won’t affect the Mode value.

HI, I am facing the same error even after replacing null values with random number.can any1 share mode part of the code

Hi @deepikah,

You can try this little hack.

Step 1: Drop the rows in the data which have NaNs
Step 2: Do the calculation of mode on this subset of data
Step 3: Impute this mode in place of NaNs in the original data

© Copyright 2013-2019 Analytics Vidhya