Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
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 |
|---|---|---|
path |
str | The path in any Hadoop-supported file system. |
mode |
str, optional | The behavior when data already exists. Accepted values are 'append', 'overwrite', 'ignore', and 'error' or 'errorifexists' (default). |
dataAddress |
str, optional | The address of the data in the Excel file. |
headerRows |
int or str, optional | The number of header rows. |
Returns
None
Examples
Write a DataFrame into an Excel file and read it back.
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|
# +-----+------------+