293-13 Data Cleaning Basics

Hi everyone :slight_smile:,

I am trying to answer this question:

What is the best value laptop with a screen size of 15" or more?

I type this code:

TOP_screen_size = (laptops[laptops['price_euros'].min()]) & (laptops[laptops['screen_size_inches'] >= 15])

But I keep having this error:

KeyError: 174
KeyError: 174.0

Why is this?

I am working with the laptops DataSet, and I’ve already converted the column price_euros to a float64 dtype!

Thanks for your help :wink:

Waddup, Abel?

I didn’t try to reproduce this behavior, but here’s a possible explanation.

In laptops[laptops['price_euros'].min()], the inner part (i.e. laptops['price_euros'].min()), is computing the minimum value in the column price_euros. It seems that the cheapest laptop costs 174.

Then laptops[laptops['price_euros'].min()] resolves to laptops[174], but 174 isn’t a column name, so you get a KeyError. Why you get two error messages I do not understand.

Anyway, what you want to do is probably something similar to what’s below, only you’ll want to replace 174 with something more elegant.

laptops[laptops['price_euros'] == 174]

Thanks! :slight_smile:

1 Like

A post was split to a new topic: Data Cleaning Basics 13