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:
Convert the DataFrame into RDD and call 'saveAsTextFile' function on it.
myresults.rdd.saveAsTextFile(OUTPUT_PATH)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 OverflowAttributeError: 'int' object has no attribute 'write'
apache spark sql - Unable to SaveAsTextFile AttributeError: 'list' object has no attribute 'saveAsTextFile' - Stack Overflow
apache spark - 'list' object has no attribute 'map' - Stack Overflow
python - AttributeError: 'SparkSession' object has no attribute 'write' - Stack Overflow
The original content here was wiped using Redact. The reason may have been privacy, security, preventing AI data collection, or simply personal data management.
marvelous spotted soft profit shaggy scale fall worm unwritten chubby