如何在 Python 中读取 gzipped parquet 文件
How can you read a gzipped parquet file in Python
我需要打开一个 gzip 文件,里面有一个镶木地板文件和一些数据。我在尝试 print/read 文件中的内容时遇到了很多麻烦。我尝试了以下方法:
with gzip.open("myFile.parquet.gzip", "rb") as f:
data = f.read()
这似乎不起作用,因为我得到一个错误,指出我的文件 ID 不是 gz 文件。谢谢!
您可以使用 pandas
模块中的 read_parquet
函数:
- 安装
pandas
和 pyarrow
:
pip install pandas pyarrow
- 使用
read_parquet
其中 returns DataFrame
:
data = read_parquet("myFile.parquet.gzip")
print(data.count()) # example of operation on the returned DataFrame
我需要打开一个 gzip 文件,里面有一个镶木地板文件和一些数据。我在尝试 print/read 文件中的内容时遇到了很多麻烦。我尝试了以下方法:
with gzip.open("myFile.parquet.gzip", "rb") as f:
data = f.read()
这似乎不起作用,因为我得到一个错误,指出我的文件 ID 不是 gz 文件。谢谢!
您可以使用 pandas
模块中的 read_parquet
函数:
- 安装
pandas
和pyarrow
:
pip install pandas pyarrow
- 使用
read_parquet
其中 returnsDataFrame
:
data = read_parquet("myFile.parquet.gzip")
print(data.count()) # example of operation on the returned DataFrame