cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
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
Valued Contributor
Valued Contributor

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
Valued Contributor
Valued Contributor

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.

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.