excel (DataFrameWriter)
Saves the content of the DataFrame in Excel format at the specified path.
Syntax
excel(path, mode=None, dataAddress=None, headerRows=None)
Parameters
Parameter | Type | Description |
|---|---|---|
| str | The path in any Hadoop-supported file system. |
| str, optional | The behavior when data already exists. Accepted values are |
| str, optional | The address of the data in the Excel file. |
| int or str, optional | The number of header rows. |
Returns
None
Examples
Write a DataFrame into an Excel file and read it back.
Python
import tempfile
with tempfile.TemporaryDirectory(prefix="excel") as d:
spark.createDataFrame(
[{"age": 100.1, "name": "Alice"}]
).write.excel(d, mode="overwrite", headerRows=1)
spark.read.option("headerRows", "1").excel(d).show()
# +-----+------------+
# | age| name|
# +-----+------------+
# |100.1|Alice|
# +-----+------------+