save
Saves the contents of the DataFrame to a data source. The data source is specified by format and a set of options. If format is not specified, the default data source configured by spark.sql.sources.default is used.
Syntax
save(path=None, format=None, mode=None, partitionBy=None, **options)
Parameters
Parameter | Type | Description |
|---|---|---|
| str, optional | The path in a Hadoop-supported file system. |
| str, optional | The format used to save. |
| str, optional | The behavior when data already exists. Accepted values are |
| list, optional | Names of partitioning columns. |
| dict | Additional string options. |
Returns
None
Examples
Write a DataFrame into a JSON file and read it back.
Python
import tempfile
with tempfile.TemporaryDirectory(prefix="save") as d:
spark.createDataFrame(
[{"age": 100, "name": "Alice"}]
).write.mode("overwrite").format("json").save(d)
spark.read.format('json').load(d).show()
# +---+------------+
# |age| name|
# +---+------------+
# |100|Alice|
# +---+------------+