Project, Ebay Car Sales: Columns names don't match in different code outputs: rename odometer to odometer_km

Screen Link: https://app.dataquest.io/m/294/guided-project%3A-exploring-ebay-car-sales-data/3/initial-exploration-and-cleaning

My Code:

autos.rename(columns= {"odometer": "odometer_km"}, copy= True)


What I expected to happen:

From the first line of code, the output successfully prints the dataset with the “odometer” column changed to “odometer_km”

What actually happened:

However, when I try to print the head of the same dataset in the next cell, it’s like the column rename is erased and the column name is again just “odometer”

autos.head()

Why does it seem to be erasing the previous rename attribute I ran?

Hello and welcome to the community!

You are not performing the operation in place, so the changes are no being stored anywhere. You are not informing the axis either.

You can do it like this:

autos.rename({"odometer": "odometer_km"}, axis=1, inplace=True)
2 Likes

I just looked back at the documentation, and that makes perfect sense… thank you!

I did the same mistake but it is solved now.

Thank you for Q&A

1 Like