Guided Project: Exploring eBay car sales step 4/9 - price and odometer return to object dtype

Hi all,

I have removed non-numeric characters on ‘price’ and ‘odometer’ column and change them into integer dtype with this code and all works well:


However, it returns to the original columns with non-numeric characters and object dtype when I typed:


and this is my code
Basics (1).ipynb (131.0 KB)

Have you guys got any thought?
Thank you.

Warm regards,

Click here to view the jupyter notebook file in a new tab

Here’s a hint. What’s happening here is the same that is happening below.

>>> x = "3" # `x` is a string
>>> int(x) # This returns an integer
>>> x

At the end x was still a string.


Hi @Bruno,

Thank you for your reply and pointing it out.
I have revised my code to:

autos['price'] = autos['price'].str.replace('$','').str.replace(',','').astype(int)
autos['price'] = autos['odometer'].str.replace(',','').str.replace('km','').astype(int)

and all works well for the next code.
Thank you very much.

Warm regards,

1 Like

hi @Bruno,
please can you help me figure out am not doing right?
price and odometer_km turned back as string
Basics (4).py (2.0 KB)

Not true. Please share a notebook (not a script) where you’re observing this behavior.

hi @Bruno,
thanks for the response.
i guess i have uploaded the right file
Basics.ipynb (115.2 KB)

Click here to view the jupyter notebook file in a new tab

I don’t see the behavior you mention in that notebook. In fact, I see opposite, both columns are int64.

thanks, i will double check

Hello, can someone please tell me what I’m doing wrong at this step? I get the KeyError ‘price’. Below is the code I used:
autos_c[“price”] = autos_c[“price”].str.replace("$","").str.replace(",","").astype(int)
autos_c[“odometer”] = autos_c[“odometer”].str.replace(“km”,"").str.replace(",","").astype(int)

autos_c.rename({“price”:“price_USD”, “odometer”:“odometer_km”}, axis=1, inplace=True)


Basics-Copy1.ipynb (188.1 KB)

Click here to view the jupyter notebook file in a new tab

I see there are quite a few cell executions that are not visible. Can you please restart your kernel, run everything and share the notebook again?

Yes, here it is below. Although, now it is not showing the error. So I guess it is fine now.