python - 有效地折叠 Parquet 中的行组
问题描述
我有一个带有许多小行组的大型 Parquet 文件。我想生成一个带有单个(更大)行组的新 Parquet 文件,并且我正在使用 Python 进行操作。我可以做类似的事情:
import pyarrow.parquet as pq
table = pq.read_table('many_tiny_row_groups.parquet')
pq.write_table(table, 'one_big_row_group.parquet')
# Lots of row groups...
print (pq.ParquetFile('many_tiny_row_groups.parquet').num_row_groups)
# Now, only 1 row group...
print (pq.ParquetFile('one_big_row_group.parquet').num_row_groups)
但是,这需要我一次将整个 Parquet 文件读入内存。我想避免这样做。是否有某种“流式处理”方法可以使内存占用保持较小?
解决方案
文档fastparquet
记录了迭代大到适合内存的数据集的可能性。对于阅读,您可以使用:
pf = ParquetFile('myfile.parquet')
for df in pf.iter_row_groups():
print(df.shape)
# process sub-data-frame df
对于写入,您可以写入append
文件。
推荐阅读
- c# - C# 通过注册表获取 Windows 驱动器硬件标题
- javascript - 反应错误 index.js:1452 警告:数组或迭代器中的每个孩子都应该有一个唯一的“键”道具
- regex - 6位数字的正则表达式彼此靠近
- elasticsearch - 在 elasticsearch 中使用多个标记进行全文搜索
- javascript - 酶 shallow() 和 addEventListener
- http - AD v2.0 端点 HTTP 重定向 url
- android - 智能转换为“TaskAdapter”是不可能的,因为“recyclerView.adapter”是一个复杂的表达式
- list - 列表在 Kentico 宏中按字母顺序排序
- nlp - 依赖解析器失败的示例
- c - C中动态数组中的未初始化值