Collect() returns all the records of the Dataframe as a list of type Row. And you are calling 'SaveAsTextFile' on the result which is a list.

List doesnt have the 'saveAsTextFile' function, so it's throwing an error.

result = myresults.collect()
result.saveAsTextFile("test")

To save the contents of the Dataframe to file, you have 2 options:

  1. Convert the DataFrame into RDD and call 'saveAsTextFile' function on it.

    myresults.rdd.saveAsTextFile(OUTPUT_PATH)

  2. Using DataframeWriter. In this case, DataFrame must have only one column that is of string type. Each row becomes a new line in the output file.

    myresults.write.format("text").save(OUTPUT_PATH)

As you have more than 1 column in Dataframe, proceed with Option:1.

Also by default, spark will create 200 Partitions for shuffle. so, 200 files will be created in the output path. If you less data, configure the below parameter according to your data size.

spark.conf.set("spark.sql.shuffle.partitions", 5) # 5 files will be written to output folder.
Answer from Lakshman Battini on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 72231354 › pyspark-getting-error-list-object-has-no-attribute-write-when-attempting-t › 72231476
databricks - pyspark - getting error 'list' object has no attribute 'write' when attempting to write to a delta table - Stack Overflow
# read from entire delta table into dataframe revEnrichRef = spark.read.format("delta").load("/mnt/tables/myTable") # retrieve first 5 rows dfSubset = revEnrichRef.head(5) dfSubset.write.format("delta").mode("overwrite").save("/mnt/tables/myTable") at this point I get the error: 'list' object has no attribute 'write'
🌐
GitHub
github.com › django-extensions › django-extensions › issues › 1151
AttributeError: 'list' object has no attribute 'write' · Issue #1151 · django-extensions/django-extensions
January 24, 2018 - self.render_output_pydot(dotdata, **options) File "/usr/local/lib/python3.4/dist-packages/django_extensions/management/commands/graph_models.py", line 151, in render_output_pydot graph.write(output_file, format=format) AttributeError: 'list' object has no attribute 'write'
Author   django-extensions
Discussions

AttributeError: 'int' object has no attribute 'write'
You have two variables. One containing the file object you want to write to, and one containing the value you want to write. However, they're both called p1_score, so when making the value you overwrite the file object, so you cannot access it anymore when trying to write to the file. More on reddit.com
🌐 r/learnpython
8
2
December 1, 2018
apache spark sql - Unable to SaveAsTextFile AttributeError: 'list' object has no attribute 'saveAsTextFile' - Stack Overflow
I have submitted a similar question relating to saveAsTextFile, but I'm not sure if one question will provide the same answer as I now have a new error messagae: I have compiled the following pysp... More on stackoverflow.com
🌐 stackoverflow.com
August 6, 2018
apache spark - 'list' object has no attribute 'map' - Stack Overflow
I do know it's cause that map is a function and not a method of list. But is there a way I can use the map function to pass data to the function called inside map. Here's my code: def func1(line... More on stackoverflow.com
🌐 stackoverflow.com
April 10, 2017
python - AttributeError: 'SparkSession' object has no attribute 'write' - Stack Overflow
can everyone help me with this one? import pandas as pd from pyspark.sql import SparkSession from pyspark import SparkConf def sql_writer(db, table_name, df, mode): server = 'my-server' usernam... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › Pyspark-issue-AttributeError-DataFrame-object-has-no › td-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 ...
🌐
Cumulative Sum
cumsum.wordpress.com › 2020 › 04 › 01 › attributeerror-list-object-has-no-attribute-_createfromlocal
AttributeError: ‘list’ object has no attribute ‘_createFromLocal’
April 1, 2020 - This error happens when you try to use SparkSession to create a data frame in a wrong way. For example, let’s say you want to create a simple data frame as follows: +—+—+ | a| b| …
🌐
Cumulative Sum
cumsum.wordpress.com › 2020 › 09 › 26 › pyspark-attributeerror-nonetype-object-has-no-attribute
[pyspark] AttributeError: ‘NoneType’ object has no attribute
February 25, 2021 - This is a generic error in python. There are a lot of reasons that can lead to this error. In pyspark, however, it’s pretty common for a beginner to make the following mistake, i.e. assign a …
🌐
Apache Spark
spark.apache.org › docs › preview › api › python › _modules › pyspark › sql › dataframe.html
pyspark.sql.dataframe — PySpark 4.1.0-preview3 documentation
September 24, 2013 - # # mypy: disable-error-code="empty-body" import sys import random from typing import ( Any, Callable, Dict, Iterator, List, Optional, Sequence, Tuple, Union, overload, TYPE_CHECKING, ) from pyspark import _NoValue from pyspark._globals import _NoValueType from pyspark.util import is_remote_only from pyspark.storagelevel import StorageLevel from pyspark.resource import ResourceProfile from pyspark.sql.column import Column from pyspark.sql.readwriter import DataFrameWriter, DataFrameWriterV2 from pyspark.sql.merge import MergeIntoWriter from pyspark.sql.streaming import DataStreamWriter from py
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 76352463 › attributeerror-sparksession-object-has-no-attribute-write
python - AttributeError: 'SparkSession' object has no attribute 'write' - Stack Overflow
The .write method is called on the Dataframe instance, not on the SparkSession instance - you need to produce a dataframe first before you can write it.
🌐
Databricks
kb.databricks.com › python › function-object-no-attribute.html
AttributeError: ‘function’ object has no attribute - Databricks
May 19, 2022 - Using protected keywords from the DataFrame API as column names results in a function object has no attribute error message.
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › AttributeError-in-Spark › td-p › 185732
Solved: AttributeError in Spark - Cloudera Community - 185732
July 18, 2018 - ## this is how to write to a hive table df.write.mode('overwrite').format('orc').saveAsTable("test") Error : AttributeError: 'HiveContext' object has no attribute 'load' ... In spark 2 you should leverage spark session instead of spark context. To read jdbc datasource just use the following code: from pyspark.sql import SparkSession from pyspark.sql import Row spark = SparkSession \ .builder \ .appName("data_import") \ .config("spark.dynamicAllocation.enabled", "true") \ .config("spark.shuffle.service.enabled", "true") \ .enableHiveSupport() \ .getOrCreate() jdbcDF2 = spark.read \ .jdbc("jdbc:sqlserver://10.24.40.29;database=CORE;username=user1;password=Passw0rd", "test")
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: ‘dataframe’ object has no attribute ‘write’ [solved]
Attributeerror: 'dataframe' object has no attribute 'write' [SOLVED] - Itsourcecode.com
April 14, 2023 - This error can be caused by a missing dependency that is required for the “write” method to work. For example, the “to_excel” method requires the openpyxl library, so if this library is not installed, you may get an error when you try ...
🌐
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
AttributeError Traceback (most recent call last) /tmp/ipykernel_7707/2196056541.py in <module> 21 22 df = spark.read\ ---> 23 .format='csv' \ 24 .option("badRecordsPath", 'abfss://*****@synapseqadatalakegen2.dfs.core.windows.net/DataLakehouse/CSV/BadCSV/.csv')\ 25 .option("mode", "PERMISSIVE")\
🌐
Databricks
community.databricks.com › s › question › 0D58Y00009IH3nkSAD › attributeerror-list-object-has-no-attribute-columns-pyspark
AttributeError: 'list' object has no attribute 'columns' - PySpark
October 3, 2022 - # reading a df for orders orders_df = spark.read.json("/public/retail_db_json/orders").dtypes # displaying the columns orders_df.columns # Error AttributeError: 'list' object has no attribute 'columns'
🌐
Saturn Cloud
saturncloud.io › blog › how-to-solve-list-object-has-no-attribute-first-error-in-pyspark-mllib-logistic-regression
Saturn Cloud | Saturn Cloud | The Control Plane for GPU Clouds
July 10, 2023 - Isolation happens at the hardware boundary, not inside a shared control plane. Each customer gets their own Kubernetes or Slurm cluster, their own InfiniBand P_Key, and their own storage namespace.
🌐
Databricks
community.databricks.com › s › question › 0D53f00001PP7DdCAL › attributeerror-nonetype-object-has-no-attribute-repartition
AttributeError: 'NoneType' object has no attribute... - Databricks Community - 13149
May 19, 2022 - AttributeError: 'NoneType' object has no attribute... ... When i don't do the write.option i am not getting below error. Why is it giving me repartition error.
🌐
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.