首页 > 解决方案 > 如何在 Python 中读取 gzipped parquet 文件

问题描述

我需要打开一个压缩文件,里面有一个镶木地板文件,里面有一些数据。我在尝试打印/读取文件中的内容时遇到了很多麻烦。我尝试了以下方法:

with gzip.open("myFile.parquet.gzip", "rb") as f:
    data = f.read()

这似乎不起作用,因为我收到一个错误,即我的文件 id 不是 gz 文件。谢谢!

标签: pythonhadoopgzipparquet

解决方案


您可以使用模块中read_parquet的功能pandas

  1. 安装pandaspyarrow
pip install pandas pyarrow
  1. 使用read_parquetwhich 返回DataFrame
data = read_parquet("myFile.parquet.gzip")
print(data.count()) # example of operation on the returned DataFrame

推荐阅读