Bemærk
Adgang til denne side kræver godkendelse. Du kan prøve at logge på eller ændre mapper.
Adgang til denne side kræver godkendelse. Du kan prøve at ændre mapper.
Loads Excel files and returns the result as a DataFrame.
Syntax
excel(path, dataAddress=None, headerRows=None, listSheets=None,
dateFormat=None, timestampFormat=None)
Parameters
| Parameter | Type | Description |
|---|---|---|
path |
str or list | One or more input paths. |
dataAddress |
str, optional | The address of the data within the Excel file. |
headerRows |
int or str, optional | The number of header rows. |
listSheets |
bool or str, optional | If True, returns the list of sheet names instead of reading data. |
dateFormat |
str, optional | The date format string. |
timestampFormat |
str, optional | The timestamp format string. |
Returns
DataFrame
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.mode("overwrite").option("headerRows", 1).excel(d)
spark.read.excel(d, headerRows=1).show()
# +-----+------------+
# | age| name|
# +-----+------------+
# |100.1|Alice|
# +-----+------------+