將內容 DataFrame 以XML格式儲存在指定路徑。
語法
xml(path, rowTag=None, mode=None, attributePrefix=None, valueTag=None,
rootTag=None, declaration=None, arrayElementName=None, nullValue=None,
dateFormat=None, timestampFormat=None, compression=None, encoding=None,
validateName=None)
參數
| 參數 | 類型 | 說明 |
|---|---|---|
path |
str | 任何支援 Hadoop 的檔案系統中的路徑。 |
mode |
力量,選用 | 當資料已經存在時的行為。 接受的值為 'append'、 'overwrite'、 'ignore'、 'error' 或 'errorifexists' (預設值)。 |
退貨
沒有
Examples
將資料框寫入 XML 檔案並讀取。
import tempfile
with tempfile.TemporaryDirectory(prefix="xml") as d:
spark.createDataFrame(
[{"age": 100, "name": "Alice"}]
).write.mode("overwrite").option("rowTag", "person").xml(d)
spark.read.option("rowTag", "person").format("xml").load(d).show()
# +---+------------+
# |age| name|
# +---+------------+
# |100|Alice|
# +---+------------+