cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

AttributeError: 'DataFrame' object has no attribute 'rename'

PHorniak
New Contributor II

Hello, I am doing the Data Science and Machine Learning course.

The Boston housing has unintuitive column names. I want to rename them, e.g. so 'zn' becomes 'Zoning'.

When I run this command:

df_bostonLegible = df_boston.rename({'zn':'Zoning'}, axis='columns')

Then I get the error "AttributeError: 'DataFrame' object has no attribute 'rename'".

I did a websearch and found a few guides that were inapplicable:

https://stackoverflow.com/questions/28163439/attributeerror-dataframe-object-has-no-attribute-height...

https://stackoverflow.com/questions/38134643/data-frame-object-has-no-attribute

1 ACCEPTED SOLUTION

Accepted Solutions

mathan_pillai
Databricks Employee
Databricks Employee

Hi @PHorniak

You can use

df_bostonLegible = df_boston.withColumnRenamed("zn", "Zoning")

please accept the answer if it works or revert back with questions

Thanks

View solution in original post

3 REPLIES 3

mathan_pillai
Databricks Employee
Databricks Employee

Hi @PHorniak

You can use

df_bostonLegible = df_boston.withColumnRenamed("zn", "Zoning")

please accept the answer if it works or revert back with questions

Thanks

iosman
New Contributor II

wow great information totally love it buddy.

KrunalLathiya
New Contributor II

If df_boston is a DataFrame, but you still face issues, try an alternative syntax: df_boston = df_boston.rename(columns={'zn': 'Zoning'}).

Make sure df_boston is a proper DataFrame and you're using a recent version of Pandas.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group