pyspark.sql.DataFrameWriter.format

DataFrameWriter.format(source: str) → pyspark.sql.readwriter.DataFrameWriter[source]

Specifies the underlying output data source.

New in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
sourcestr

string, name of the data source, e.g. ‘json’, ‘parquet’.

Examples

>>> spark.range(1).write.format('parquet')
<...readwriter.DataFrameWriter object ...>

Write a DataFrame into a Parquet file and read it back.

>>> import tempfile
>>> with tempfile.TemporaryDirectory() as d:
...     # Write a DataFrame into a Parquet file
...     spark.createDataFrame(
...         [{"age": 100, "name": "Hyukjin Kwon"}]
...     ).write.mode("overwrite").format("parquet").save(d)
...
...     # Read the Parquet file as a DataFrame.
...     spark.read.format('parquet').load(d).show()
+---+------------+
|age|        name|
+---+------------+
|100|Hyukjin Kwon|
+---+------------+