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
🌐
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...
🌐
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 - As the error message states, the ...#org.apache.spark.rdd.RDD ... To save a DataFrame as a text file in PySpark, you need to convert it to an RDD first, or use DataFrame writer functions....
🌐
AWS re:Post
repost.aws › questions › QUvWrsRjenSrqHLJqLpy4DWg › attributeerror-dataframe-object-has-no-attribute-get-object-id
AttributeError: 'DataFrame' object has no attribute '_get_object_id' | AWS re:Post
October 11, 2018 - Traceback (most recent call last): File "/tmp/zeppelin_pyspark-444437833802934152.py", line 367, in <module> raise Exception(traceback.format_exc()) Exception: Traceback (most recent call last): File "/tmp/zeppelin_pyspark-444437833802934152.py", line 355, in <module> exec(code, _zcUserQueryNameSpace) File "<stdin>", line 55, in <module> File "/usr/share/aws/glue/etl/python/PyGlue.zip/awsglue/dynamicframe.py", line 591, in from_catalog return self._glue_context.write_dynamic_frame_from_catalog(frame, db, table_name, redshift_tmp_dir, transformation_ctx, additional_options) File "/usr/share/aws
🌐
Incorta Community
community.incorta.com › t5 › data-schemas-knowledgebase › issue-with-converting-a-pandas-dataframe-to-a-spark-dataframe › ta-p › 5279
Issue with converting a Pandas DataFrame to a Spar... - Incorta Community
November 15, 2023 - Symptoms You received the error when trying to convert a Pandas DataFrame to Spark DataFrame in a PySpark MV. Here is the error.- INC_03070101: Transformation error Error 'DataFrame' object has no attribute 'iteritems' AttributeError : 'DataFrame' object has no attribute 'iteritems' Diagnosis Since...
🌐
GitHub
github.com › microsoft › FLAML › issues › 625
AttributeError: 'DataFrame' object has no attribute 'copy' · Issue #625 · microsoft/FLAML
July 2, 2022 - train = spark.read.parquet("./train.parquet") test = spark.read.parquet("./test.parquet") input_cols = [c for c in train.columns if c != 'target'] vectorAssembler = VectorAssembler(inputCols = input_cols, outputCol = 'features') vectorAssembler.setHandleInvalid("skip").transform(train).show train_sprk = vectorAssembler.transform(train) test_sprk = vectorAssembler.transform(test) from sklearn.model_selection import train_test_split from sklearn.datasets import make_classification y = train_sprk["target"] X = train_sprk[input_cols] X, y = make_classification() X_train, X_test, y_train, y_test =
Author   Shafi2016
Find elsewhere
🌐
Hail Discussion
discuss.hail.is › help [0.1]
AttributeError: 'DataFrame' object has no attribute 'to_spark' - Help [0.1] - Hail Discussion
July 22, 2018 - I am trying to covert a Hail table to a pandas dataframe: kk2 = hl.Table.to_pandas(table1) # convert to pandas I am not sure why I am getting this error: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) in 1 kk2 = hl.Table.to_pandas(table1) # convert to pandas /home/hail/hail.zip/hail/typecheck/check.py in wrapper(*args, **kwargs) 545 ...
🌐
Cumulative Sum
cumsum.wordpress.com › 2020 › 10 › 10 › pyspark-attributeerror-dataframe-object-has-no-attribute-_get_object_id
[pyspark] AttributeError: ‘DataFrame’ object has no attribute ‘_get_object_id’
October 10, 2020 - AttributeError: ‘DataFrame’ object has no attribute ‘_get_object_id’ · The reason being that isin expects actual local values or collections but df2.select('id') returns a data frame.
🌐
JetBrains
intellij-support.jetbrains.com › hc › en-us › community › posts › 360003244439-Error-viewing-pyspark-DataFrame
Error viewing pyspark DataFrame – IDEs Support (IntelliJ Platform) | JetBrains
I think this is more than just supporting the view in the scientific table viewer: this actually causes errors to pop up in a bunch of places when working in a pandas/pyspark environment... e.g. even trying to print out some info about the spark DF in the `evaluate expression` box fails with the error `AttributeError: 'DataFrame' object has no attribute 'shape'`
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)
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › Pyspark-issue-AttributeError-DataFrame-object-has-no › m-p › 381546
Re: Pyspark issue AttributeError: 'DataFrame' object has no attribute 'saveAsTextFile'
January 2, 2024 - To save a DataFrame as a text file in PySpark, you need to convert it to an RDD first, or use DataFrame writer functions. Using DataFrame writer: df.write.format("text").save("path_to_output_directory") Converting to RDD and then using saveAsTextFile rdd = df.rdd.map(lambda row: str(row)) ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 927325 › trouble-with-spark-code-in-notebook-str-object-has
Trouble with spark code in Notebook, 'str' object has no attribute 'option - Microsoft Q&A
import sys from pyspark import SparkContext from pyspark.sql import SparkSession from pyspark.sql.types import * spark = SparkSession \ .builder \ .appName("Validate") \ .getOrCreate custumSchema = StructType([ StructField("A#", IntegerType(), True), StructField("FirstName", StringType(), True),\ StructField("LastName", StringType(), True),\ StructField("DOB",DateType(), True),\ StructField("Gender", StringType(), True ),\ StructField("corrupt_record", StringType(), True )\ ]) df = spark.read\ .format='csv' \ .option("badRecordsPath", 'abfssXXXXXXCSV/BadCSV/*.csv')\ .option("mode", "PERMISSIVE")\ .options(header='true', delimiter=',',) \ .option("columnNameOfCorruptRecord", "corrupt_record") \ .load('abfss://synapXXXXXXXCSV/*.csv', schema = custumSchema) df.show()
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: ‘dataframe’ object has no attribute ‘_jdf’ [solved]
Attributeerror: 'dataframe' object has no attribute '_jdf' [SOLVED]
March 24, 2023 - To resolve the issue, check your code to ensure that you are only using Pandas methods and attributes on Pandas data frames, and PySpark methods and attributes on PySpark data frames.
🌐
Spark By {Examples}
sparkbyexamples.com › home › hbase › attributeerror: ‘dataframe’ object has no attribute ‘map’ in pyspark
AttributeError: 'DataFrame' object has no attribute 'map' in PySpark - Spark By {Examples}
April 3, 2021 - Problem: In PySpark I am getting error AttributeError: 'DataFrame' object has no attribute 'map' when I use map() transformation on DataFrame.