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'})
Answer from Merlin on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › "'dataframe' object has no attribute" issue
r/learnpython on Reddit: "'DataFrame' object has no attribute" Issue
October 30, 2020 -

I am in university and am taking a special topics class regarding AI. I have zero knowledge about Python, how it works, or what anything means.

A project for the class involves manipulating Bayesian networks to predict how many and which individuals die upon the sinking of a ship. This is the code I am supposed to manipulate:

##EDIT VARIABLES TO THE VARIABLES OF INTEREST
train_var = train.loc[:,['Survived','Sex']]  
test_var = test.loc[:,['Sex']]  
BayesNet = BayesianModel([('Sex','Survived')])

I am supposed to add another variable, 'Pclass,' to the mix, paying attention to the order for causation. I have added that variable to every line of this code in every way imaginable and consistently get an error from this line:

predictions = pandas.DataFrame({'PassengerId': test.PassengerId,'Survived': hypothesis.Survived.tolist()})
predictions

For example, the error I get for this version of the code:

train_var = train.loc[:,['Survived','Pclass','Sex']]  
test_var = test.loc[:,['Pclass']]  
BayesNet = BayesianModel([('Sex','Pclass','Survived')])

is this:

AttributeError                            Traceback (most recent call last)
<ipython-input-98-16d9eb9451f7> in <module>
----> 1 predictions = pandas.DataFrame({'PassengerId': test.PassengerId,'Survived': hypothesis.Survived.tolist()})
      2 predictions

/opt/conda/lib/python3.7/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5137             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5138                 return self[name]
-> 5139             return object.__getattribute__(self, name)
   5140 
   5141     def __setattr__(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'Survived'

Honestly, I have no idea wtf any of this means. I have tried googling this issue and have come up with nothing.

Any help would be greatly appreciated. I know it's a lot.

Discussions

python - GeoPandas: AttributeError: 'DataFrame' object has no attribute 'to_file'. Did you mean: 'to_pickle'? - Geographic Information Systems Stack Exchange
I am at a complete loss, I have looked at other posts to no avail. Following is the code I am trying to execute: import os import geopandas as gpd root_dir = r"C:\Users\s.oneill\Desktop\SAMPLE... More on gis.stackexchange.com
🌐 gis.stackexchange.com
July 27, 2023
AttributeError: 'DataFrame' object has no attribute 'name'
AttributeError Traceback (most ... -> 5067 return object.__getattribute__(self, name) 5068 5069 def __setattr__(self, name, value): AttributeError: 'DataFrame' object has no attribute 'name'... More on github.com
🌐 github.com
18
December 18, 2019
python - I got the following error : 'DataFrame' object has no attribute 'data' - Data Science Stack Exchange
I am trying to get the 'data' and the 'target' of the iris setosa database, but I can't. For example, when I load the iris setosa directly from sklearn datasets I get a good result: Program: from More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
August 26, 2018
AttributeError: 'DataFrame' object has no attribute 'data'
I would recommend you start off by reading the 10min pandas Quick Guide . This should get you on the right track (at the very least you will be able to load data into pandas). Afterwards, you should also be able to tell why your current code doesn't make much sense. More on reddit.com
🌐 r/learnpython
4
0
September 29, 2021
🌐
GitHub
github.com › dask › dask › issues › 8624
AttributeError: 'DataFrame' object has no attribute 'name'; Various stack overflow / github suggested fixes not working · Issue #8624 · dask/dask
January 26, 2022 - { File "[redacted]/pandas/core/generic.py", line 5487, in __getattr__ return object.__getattribute__(self, name) AttributeError: 'DataFrame' object has no attribute 'name'. Did you mean: 'rename'? }
Author   david-thrower
🌐
Brainly
brainly.com › computers and technology › high school › how to resolve attributeerror: 'dataframe' object has no attribute?
[FREE] How to resolve AttributeError: 'DataFrame' object has no attribute? - brainly.com
When you encounter the error message AttributeError: 'DataFrame' object has no attribute, it usually means you're trying to access a column or method that doesn't exist in a pandas DataFrame.
🌐
Databricks Community
community.databricks.com › t5 › data-engineering › attributeerror-dataframe-object-has-no-attribute › td-p › 61132
AttributeError: 'DataFrame' object has no attribut... - Databricks Community - 61132
February 19, 2024 - Hello, I have some trouble deduplicating rows on the "id" column, with the method "dropDuplicatesWithinWatermark" in a pipeline. When I run this pipeline, I get the error message: "AttributeError: 'DataFrame' object has no attribute 'dropDuplicatesWithinWatermark'" Here is part of the code: @dl...
🌐
GitHub
github.com › scikit-learn-contrib › imbalanced-learn › issues › 666
AttributeError: 'DataFrame' object has no attribute 'name' · Issue #666 · scikit-learn-contrib/imbalanced-learn
December 18, 2019 - AttributeError Traceback (most ... -> 5067 return object.__getattribute__(self, name) 5068 5069 def __setattr__(self, name, value): AttributeError: 'DataFrame' object has no attribute 'name'...
Author   islrnd
Top answer
1 of 5
2

"sklearn.datasets" is a scikit package, where it contains a method load_iris().

load_iris(), by default return an object which holds data, target and other members in it. In order to get actual values you have to read the data and target content itself.

Whereas 'iris.csv', holds feature and target together.

FYI: If you set return_X_y as True in load_iris(), then you will directly get features and target.

from sklearn import datasets
data,target = datasets.load_iris(return_X_y=True)
2 of 5
1

The Iris Dataset from Sklearn is in Sklearn's Bunch format:

print(type(iris))
print(iris.keys())

output:

<class 'sklearn.utils.Bunch'>
dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names', 'filename'])

So, that's why you can access it as:

x=iris.data
y=iris.target

But when you read the CSV file as DataFrame as mentioned by you:

iris = pd.read_csv('iris.csv',header=None).iloc[:,2:4]
iris.head()

output is:

    2   3
0   petal_length    petal_width
1   1.4 0.2
2   1.4 0.2
3   1.3 0.2
4   1.5 0.2

Here the column names are '1' and '2'.

First of all you should read the CSV file as:

df = pd.read_csv('iris.csv')

you should not include header=None as your csv file includes the column names i.e. the headers.

So, now what you can do is something like this:

X = df.iloc[:, [2, 3]] # Will give you columns 2 and 3 i.e 'petal_length' and 'petal_width'
y = df.iloc[:, 4] # Label column i.e 'species'

or if you want to use the column names then:

X = df[['petal_length', 'petal_width']]
y = df.iloc['species']

Also, if you want to convert labels from string to numerical format use sklearn LabelEncoder

from sklearn import preprocessing
le = preprocessing.LabelEncoder()
y = le.fit_transform(y)
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › attributeerror: 'dataframe' object has no attribute 'data'
r/learnpython on Reddit: AttributeError: 'DataFrame' object has no attribute 'data'
September 29, 2021 -
wine = pd.read_csv("combined.csv", header=0).iloc[:-1]
df = pd.DataFrame(wine)
df
dataset = pd.DataFrame(df.data, columns =df.feature_names)
dataset['target']=df.target
dataset

ERROR:

<ipython-input-27-64122078da92> in <module>
----> 1 dataset = pd.DataFrame(df.data, columns =df.feature_names)
      2 dataset['target']=df.target
      3 dataset

D:\Anaconda\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
   5463             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5464                 return self[name]
-> 5465             return object.__getattribute__(self, name)
   5466 
   5467     def __setattr__(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'data'

I'm trying to set up a target to proceed with my Multi Linear Regression Project, but I can't even do that. I've already downloaded the CSV file and have it uploaded on a Jupyter Notebook. What I'm I doing wrong?

🌐
Data Science Dojo
discuss.datasciencedojo.com › python
AttributeError: 'DataFrame' object has no attribute 'row_count' - Python - Data Science Dojo Discussions
May 3, 2023 - I’m having some trouble getting the row count of a Pandas DataFrame using Python. I’m pretty new to Pandas, so I’m not sure what I’m doing wrong. Here’s the code I have: When I run this code, I get the following error message: AttributeError: 'DataFrame' object has no attribute ...
🌐
Saturn Cloud
saturncloud.io › blog › solving-the-dataframe-object-has-no-attribute-name-error-in-pandas
Solving the 'DataFrame Object Has No Attribute 'name' Error in Pandas | Saturn Cloud Blog
November 2, 2023 - Before we delve into the solution, let’s understand the error. The 'DataFrame' object has no attribute 'name' error typically occurs when you try to access a DataFrame’s 'name' attribute, which doesn’t exist.
🌐
Software House
softwarehouse.au › home › blog › how to resolve attributeerror dataframe object has no attribute append in pandas
Fix: Pandas DataFrame 'append' Attribute Error
March 2, 2026 - The error, displayed as AttributeError: 'DataFrame' object has no attribute 'append' or, more helpfully, AttributeError: 'DataFrame' object has no attribute 'append'. Did you mean: '_append'?, signals the removal of the append() method from DataFrame objects.
🌐
HoloViz Discourse
discourse.holoviz.org › panel
AttributeError: 'NoneType' object has no attribute 'lookup' - Panel - HoloViz Discourse
February 13, 2023 - I have the following code to create a dasboard. It works fine. I mean it produces the plots and figures. wgt_schoolSelected = pn.widgets.Select(name='Okul Seçiniz:', options=list(classSchool.Name.unique())) nQuestionsPerExam = pn.widgets.IntSlider(name='Min.
🌐
GitHub
github.com › pandas-profiling › pandas-profiling › issues › 183
AttributeError: 'DataFrame' object has no attribute 'profile_report' · Issue #183 · ydataai/ydata-profiling
June 22, 2019 - ------------------------------... -> 5067 return object.__getattribute__(self, name) 5068 5069 def __setattr__(self, name, value): AttributeError: 'DataFrame' object has no attribute 'profile_report'...
Author   bdch1234
🌐
Quora
quora.com › How-do-you-fix-pandas-that-have-no-attribute-dataframe
How to fix pandas that have no attribute dataframe - Quora
Answer (1 of 2): There are three possibilities here : * The filename could be pandas.py * The filename could be whatever you have imported as, for example, pd. You could have imported using import pandas as pd * There is another file with the name pandas.py or pd.py in the current directory W...
🌐
Edureka Community
edureka.co › community › 42320 › python-pandas-attributeerror-dataframe-object-attribute
Python Pandas error AttributeError DataFrame object has ...
March 28, 2019 - Host '172.31.27.232' is blocked because of many connection errors; unblock with 'mariadb-admin flush-hosts'