Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data-frame Object has no Attribute

Tags:

python

pandas

csv

I know that this kind of question was asked before and I've checked all the answers and I have tried several times to find a solution but in vain. In fact I call a Dataframe using Pandas. I've uploaded a csv.file.

dataset from csv

When I type data.Country and data.Year, I get the 1st Column and the second one displayed. However when I type data.Number, everytime it gives me this error:

AttributeError: 'DataFrame' object has no attribute 'Number'.

like image 858
Mouna Belaid Avatar asked Jun 30 '16 23:06

Mouna Belaid


People also ask

How do you solve a DataFrame object has no attribute?

If you try to call concat() on a DataFrame object, you will raise the AttributeError: 'DataFrame' object has no attribute 'concat'. You have to pass the columns to concatenate to pandas. concat() and define the axis to concatenate along.

Which is not an attribute of DataFrame object?

the reason of " 'DataFrame' object has no attribute 'Number'/'Close'/or any col name " is because you are looking at the col name and it seems to be "Number" but in reality it is " Number" or "Number " , that extra space is because in the excel sheet col name is written in that format.

What is a DataFrame object?

DataFrame is a 2-dimensional labeled data structure with columns of potentially different types. You can think of it like a spreadsheet or SQL table, or a dict of Series objects. It is generally the most commonly used pandas object.


1 Answers

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'}) 
like image 54
Merlin Avatar answered Sep 22 '22 13:09

Merlin