将 Parquet 格式的内容 DataFrame 保存在指定的路径上。
Syntax
parquet(path, mode=None, partitionBy=None, compression=None)
参数
| 参数 | 类型 | 说明 |
|---|---|---|
path |
str | 任何 Hadoop 支持的文件系统中的路径。 |
mode |
str,可选 | 数据已存在时的行为。 接受的值是 'append'、 'overwrite'、 'ignore'或 'error''errorifexists' (默认值)。 |
partitionBy |
str 或 list,可选 | 分区列的名称。 |
compression |
str,可选 | 要使用的压缩编解码器。 |
退货
没有
示例
将 DataFrame 写入 Parquet 文件,并将其读回。
import tempfile
with tempfile.TemporaryDirectory(prefix="parquet") as d:
spark.createDataFrame(
[{"age": 100, "name": "Alice"}]
).write.parquet(d, mode="overwrite")
spark.read.format("parquet").load(d).show()
# +---+------------+
# |age| name|
# +---+------------+
# |100|Alice|
# +---+------------+