AttributeError: 'tuple' object has no attribute for the code below

Viewed 2362

I am new to programming and python. Could you please help me with the reason for this error? I have listed the error below.

Code -

country_data_complete = country_data_complete.drop(columns=["City_y", "Host_Country"]),

country_data_complete = country_data_complete.rename({'City_x':'Host_City', 'wb_country_code':'Country_code', 'No. of Atheletes':'No_of_Athelets','Medal':'Total', 'Country':'Country_Name'})

country_data_complete.head()

Error -

AttributeError: 'tuple' object has no attribute 'rename'
2 Answers

There is a comma (,) at the end of the first line. It should not be there =p

Indeed, there a , that shouldn't be there, so the code should look like this (I added a variable to store the data that you are sending to .rename to simplify):

country_data_complete = country_data_complete.drop(columns=["City_y", "Host_Country"])

dict = {'City_x': 'Host_City', 
        'wb_country_code': 'Country_code',
        'No. of Atheletes': 'No_of_Athelets',
        'Medal': 'Total', 
        'Country': 'Country_Name'
        }

country_data_complete = country_data_complete.rename(dict)

country_data_complete.head()
Related