Ebay Car Sales - Key error when uploaded to my Jupyter

The coding portion of my project is done in the Dataquest testing environment but I get a key error when trying to remove string values from the odometer and price columns on my personal Jupyter notebook. The full project can be found here with the problem at IN[44];

My Code:

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

autos['odometer'] = autos['odometer'].str.replace('km','')
autos['odometer'] = autos['odometer'].str.replace(',','')
autos['odometer'] = autos['odometer'].astype(int)
autos = autos.rename({'odometer':'odometer_km'}, axis=1)

What I expected to happen: The code to run as normal by removing strings and renaming columns.

What actually happened: Key Error: 'odometer' — full error details on project link

I understand my code here could be condensed but I am more concerned about understanding why errors occur when uploading .ipynb files to my pc. Any help and general suggestions about the project would be much appreciated.

Hey @evanmcf.16

I saw your code and in cell 44 you are trying to rename the column name odometer into odometer. But initially there is no any column in autos dataset as odometer. You are applying operations on not existed column (according to your dataset).

That’s why you are getting KeyError .

1 Like