Most probably your DataFrame is the Pandas DataFrame object, not Spark DataFrame object.

try:

spark.createDataFrame(df).write.saveAsTable("dashboardco.AccountList")
Answer from Alex Ott on Stack Overflow
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: ‘dataframe’ object has no attribute ‘write’ [solved]
Attributeerror: 'dataframe' object has no attribute 'write' [SOLVED]
April 14, 2023 - In conclusion the error “AttributeError: ‘DataFrame’ object has no attribute ‘write'” occurs when the code is trying to use an invalid method to write a Pandas DataFrame object to a file.
Discussions

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
python - AttributeError: 'DataFrame' object has no attribute 'write' - Stack Overflow
I'm trying to write dataframe 0dataframe to a different excel spreadsheet but getting this error, any ideas? #imports import numpy as np import pandas as pd #client data, data frame excel_1 = pd. More on stackoverflow.com
🌐 stackoverflow.com
January 23, 2020
"'DataFrame' object has no attribute" Issue

Double check if there's a space in the column name. 'Survived ' vs 'Survived' It happens more often than you'd think especially with CSV data source.

More on reddit.com
🌐 r/learnpython
8
1
October 30, 2020
AttributeError: 'DataFrame' object has no attribute 'name'; Various stack overflow / github suggested fixes not working
What happened: I perform a pipeline of transformations on a Dask dataframe originating from dd.read_sql_table() from a view in an oracle DB. In one stage that follows many successful stages, I try ... More on github.com
🌐 github.com
10
January 26, 2022
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › Pyspark-issue-AttributeError-DataFrame-object-has-no › m-p › 78093
Pyspark issue AttributeError: 'DataFrame' object has no attribute 'saveAsTextFile'
January 2, 2024 - So, if someone could help resolve this issue that would be most appreciated ... As the error message states, the object, either a DataFrame or List does not have the saveAsTextFile() method. result.write.save() or result.toJavaRDD.saveAsTextFile() shoud do the work, or you can refer to DataFrame ...
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)
🌐
Microsoft Fabric Community
community.fabric.microsoft.com › t5 › Service › Fabric-Notebook-write-dataframe-to-lakehouse-fails-DataFrame › m-p › 4421535
Re: Fabric Notebook - write dataframe to lakehouse fails - 'DataFrame' object has no attri
February 21, 2025 - Does anyone have a working solution ... much appreciated Kind regards · Solved! Go to Solution. ... You definitely need to convert to a spark dataframe before writing....
🌐
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...
Find elsewhere
🌐
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.

🌐
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 - Starting with a Dask dataframe returned by a chain of upstream sorting and filtering operations (df.query(), boolean masking, etc ...) on an original dataframe returned by dd.read_sql_table() from an Oracle DB which looks like this: { # house_id city_and_state district ... has_leaky_roof owes_taxes # <object> <object> <object> <object> <object> # 1 "1" "Tempe, AZ" "Tempe, AZ, University" "no" "no" # 2 "17" "Santa Monica, CA" 'Santa Monica, CA N, Ocean' "no" "no" }
Author   david-thrower
🌐
Dataiku Community
community.dataiku.com › questions & discussions › using dataiku
AttributeError: DataFrame object has no attribute _session — Dataiku Community
August 3, 2022 - Use dataset.write_dataframe() instead.") 154 --> 155 df_connection_name = df._session.dss_connection_name if hasattr(df._session, "dss_connection_name") else None 156 dataset_config = dataset.get_config() 157 dataset_info = dataset.get_location_info()["info"] /data/dataiku/datadir/code-envs/python/snowpark/lib/python3.8/site-packages/snowflake/snowpark/dataframe.py in __getattr__(self, name) 521 # Snowflake DB ignores cases when there is no quotes. 522 if name.lower() not in [c.lower() for c in self.columns]: --> 523 raise AttributeError( 524 f"{self.__class__.__name__} object has no attribute {name}" 525 ) AttributeError: DataFrame object has no attribute _session
🌐
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
The 'AttributeError: 'DataFrame' object has no attribute' suggests that a nonexistent attribute is being accessed on a DataFrame. Check the DataFrame's structure and ensure columns are correctly typed.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-fix-module-pandas-has-no-attribute-dataframe
How to Fix: module ‘pandas’ has no attribute ‘dataframe’ - GeeksforGeeks
December 19, 2021 - Attributes are the properties of a DataFrame that can be used to fetch data or any information related to a particular dataframe. The syntax of writing an attribute is: DataFrame_name.attribute These are the attributes of the · 11 min read How to fix AttributeError: module numpy has no attribute float' in Python
🌐
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'
🌐
Databricks Community
community.databricks.com › t5 › data-engineering › attributeerror-dataframe-object-has-no-attribute-rename › td-p › 28109
Solved: AttributeError: 'DataFrame' object has no attribut... - Databricks Community - 28109
January 2, 2024 - Hello, I am doing the Data Science and Machine Learning course. The Boston housing has unintuitive column names. I want to rename them, e.g. so 'zn' becomes 'Zoning'. When I run this command: df_bostonLegible = df_boston.rename({'zn':'Zoning'}, axis='columns') Then I get the error "AttributeError: '...
🌐
Python Forum
python-forum.io › thread-39437.html
Pandas AttributeError: 'DataFrame' object has no attribute 'concat'
Dears I am trying to merge multiple excel files into a single file with Python, but I get an error and I can't fix it. My Code is import os import pandas as pd cwd = os.path.abspath('') files = os.listdir(cwd) folder = r'C:\Users\Sameer\Downloa...
🌐
GitHub
github.com › YosefLab › Compass › issues › 92
AttributeError: 'DataFrame' object has no attribute 'iteritems' · Issue #92 · YosefLab/Compass
April 5, 2023 - "Evaluating Reaction Pentalties:" Traceback (most recent call last): File "/home/ubuntu/.local/bin/compass", line 8, in sys.exit(entry()) File "/home/ubuntu/.local/lib/python3.8/site-packages/compass/main.py", line 588, in entry penalties = eval_reaction_penalties(args['data'], args['model'], File "/home/ubuntu/.local/lib/python3.8/site-packages/compass/compass/penalties.py", line 96, in eval_reaction_penalties reaction_penalties = eval_reaction_penalties_shared( File "/home/ubuntu/.local/lib/python3.8/site-packages/compass/compass/penalties.py", line 158, in eval_reaction_penalties_shared for name, expression_data in expression.iteritems(): File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/generic.py", line 5989, in getattr return object.getattribute(self, name) AttributeError: 'DataFrame' object has no attribute 'iteritems'
Author   JoelHaas