- parquet 文件的处理
parquet 文件的读取
pandas
import pandas as pd
df = pd.read_parquet('file.parquet')
# 剩余操作与 csv 操作相同PyArrow
pip install pyarrow方案一 - 转换为 pd.Dataframe 格式
import pyarrow.parquet as pq
table = pq.read_table('file.parquet')
df = table.to_pandas()方案二 - 分批读取
有时候,parquet 文件较大,一次读取一个文件可能会占用很大空间,因此选择一个个 row group 进行读取。
target_entity_pq_file = pq.ParquetFile(target_entity_file_path)
for row_group in range(target_entity_pq_file.num_row_groups):
table = target_entity_pq_file.read_row_group(row_group)
req_ids.extend([item.as_py() for item in table['reqId']])
# as_py 函数,将类型转换为 python 内置的格式