在 Python 中获取镶木地板文件的架构 [英] Get schema of parquet file in Python

查看:54
本文介绍了在 Python 中获取镶木地板文件的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何 Python 库可用于获取 Parquet 文件的架构?

Is there any python library that can be used to just get the schema of a parquet file?

目前我们正在将镶木地板文件加载到 Spark 中的数据帧中,并从数据帧中获取模式以显示在应用程序的某些 UI 中.但是初始化 spark-context 和加载数据帧并从数据帧中获取模式是耗时的活动.因此,正在寻找一种替代方法来获取架构.

Currently we are loading the parquet file into dataframe in Spark and getting schema from the dataframe to display in some UI of the application. But initializing spark-context and loading data frame and getting the schema from dataframe is time consuming activity. So looking for an alternative way to just get the schema.

推荐答案

除了@mehdio 的回答,如果您的镶木地板是一个目录(例如由 spark 生成的镶木地板),要读取架构/列名称:

In addition to the answer by @mehdio, in case your parquet is a directory (e.g. a parquet generated by spark), to read the schema / column names:

import pyarrow.parquet as pq
pfile = pq.read_table("file.parquet")
print("Column names: {}".format(pfile.column_names))
print("Schema: {}".format(pfile.schema))

这篇关于在 Python 中获取镶木地板文件的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆