user356
user356

Reputation: 323

AttributeError when trying to rename columns

So I tried to rename columns so that it looks cleaner when it outputs in Jupyter notebook:

df = df.rename(columns={'i_Team':'I Team', 'Full_Name':'Full Name'}, inplace = True)

But I get the following error:

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

Any idea what could be causing the issue? Thanks in advance!

Upvotes: 1

Views: 3279

Answers (1)

Ashu Grover
Ashu Grover

Reputation: 757

Your df is not a dataframe object but a Styler object. First convert it into the dataframe object using:

final_df = df.data

then apply,

final_df.rename(columns={'i_Team':'I Team', 'Full_Name':'Full Name'}, inplace = True)

Also, please note that you need not re-assign to original variable when using inplace=True

Upvotes: 1

Related Questions