close

[Solved] AttributeError: ‘DataFrame’ object has no attribute

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: ‘DataFrame’ object has no attribute in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: ‘DataFrame’ object has no attribute Error Occurs?

Today I get the following error AttributeError: ‘DataFrame’ object has no attribute in python.

How To Solve AttributeError: ‘DataFrame’ object has no attribute Error ?

  1. How To Solve AttributeError: 'DataFrame' object has no attribute Error ?

    To Solve AttributeError: 'DataFrame' object has no attribute Error Check for hidden white spaces..Then you can rename with
    data = data.rename(columns={'Number ': 'Number'})

  2. AttributeError: 'DataFrame' object has no attribute

    To Solve AttributeError: 'DataFrame' object has no attribute Error Check for hidden white spaces..Then you can rename with
    data = data.rename(columns={'Number ': 'Number'})

Solution 1

I’m going to take a guess. I think the column name that contains "Number" is something like " Number" or "Number ". Notice that I’m assuming you might have a residual space in the column name somewhere. Do me a favor and run print "<{}>".format(data.columns[1]) and see what you get. Is it something like < Number>? If so, then my guess was correct. You should be able to fix it with this:

data.columns = data.columns.str.strip()

Solution 2

Check your DataFrame with data.columns

It should print something like this

Index([u'regiment', u'company',  u'name',u'postTestScore'], dtype='object')

Check for hidden white spaces..Then you can rename with

data = data.rename(columns={'Number ': 'Number'})

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read