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

Screen Link:

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”


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)

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

Hello everyone,

has the dataset changed?

I have already modified the price column to a numeric dtype, and the odometer column is called kilometer and it is also a numeric dtype.