mode (DataFrameWriter)
Specifies the behavior when data or table already exists.
Syntax
mode(saveMode)
Parameters
Parameter | Type | Description |
|---|---|---|
| str | The save mode. Accepted values are |
Returns
DataFrameWriter
Examples
Write a Parquet file back with various modes, and read it back.
Python
import tempfile
with tempfile.TemporaryDirectory(prefix="mode") as d:
# Overwrite the path with a new Parquet file
spark.createDataFrame(
[{"age": 100, "name": "Alice"}]
).write.mode("overwrite").format("parquet").save(d)
# Append another DataFrame into the Parquet file
spark.createDataFrame(
[{"age": 120, "name": "Sue"}]
).write.mode("append").format("parquet").save(d)
# Read the Parquet file as a DataFrame.
spark.read.parquet(d).show()
# +---+-------------+
# |age| name|
# +---+-------------+
# |120| Sue |
# |100| Alice |
# +---+-------------+