I cannot remove outlier in Ebay car-sale guided project (step 4)


My code is as follow:

too_cheap = autos["price_US"] < 100
too_expensive = autos["price_US"] > 350000
autos.loc[too_cheap & too_expensive, "price_US"] = np.nan

I expected the prices less than 100 and more than 350000 turned into NaN value. But when I test with

print(autos["price_US"].value_counts(ascending = False)

Those values still there. Please help.

Hey, Minhaa.

The mask too_cheap & too_expensive is subsetting all prices that are below 100 and higher than 35000. There are no numbers that are simultaneously lower than 100 and higher than 35000, so your code is changing no values to numpy.NaN.

Can you fix your code now?

1 Like

I should had used the or argument shouldn’t I? Woalah. It fixed. Thank you Bruno.

1 Like