- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2019 04:20 PM
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/38134643/data-frame-object-has-no-attribute
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2019 03:05 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2019 05:35 AM
wow great information totally love it buddy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-02-2024 02:50 AM
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.