Notă
Accesul la această pagină necesită autorizare. Puteți încerca să vă conectați sau să modificați directoarele.
Accesul la această pagină necesită autorizare. Puteți încerca să modificați directoarele.
Specifies the behavior when data or table already exists.
Syntax
mode(saveMode)
Parameters
| Parameter | Type | Description |
|---|---|---|
saveMode |
str | The save mode. Accepted values are 'append' (append to existing data), 'overwrite' (overwrite existing data), 'error' or 'errorifexists' (throw an exception if data exists), and 'ignore' (silently skip if data exists). |
Returns
DataFrameWriter
Examples
Write a Parquet file back with various modes, and read it back.
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 |
# +---+-------------+