Confusion in replacing aggfunc by np.median() or np.mean() while using pivot table for 'LoanAmount'


#1

While I was preparing a pivot table for substituting missing values of Loan Amount(using index as ‘SELF_EMPLOYED’ and columns as’EDUCATION’), why did Kunal Sir in his blog replaced values by median of each group rather than the mean i.e in aggfunc he used np.median(). I wonder why he used median instead of np.mean().??


#2

Does it have to do anything with the fact that mean includes sum of values which include outliers as well???


#3

Hi @sahil1995chaturvedi

Yes, your intuition is correct as in the case where we have outliers we generally prefer imputing missing values with the median.

Although, you should always try and experiment that what better suits your data through cross-validation.

Cheers!
Shubham


#4

Thanks for your reply @shubham.jain.
Will do that !!! Thanks :slight_smile: