如何使用Python Pandas读取.arrow(Apache Arrow/Feather V2格式)文件?
读取Apache Arrow格式文件的方法
要读取.arrow格式文件,你可以借助pyarrow库实现,下面是两种常用方案:
方案一:先读取为pyarrow.Table,再转为pandas.DataFrame
- 先安装依赖库:
pip install pyarrow
- 读取Arrow文件为pyarrow.Table:
import pyarrow as pa # 打开并读取整个Arrow文件 with pa.ipc.open_file("target_file.arrow") as reader: arrow_table = reader.read_all()
- 将pyarrow.Table转为pandas.DataFrame:
import pandas as pd df = arrow_table.to_pandas()
方案二:直接用pandas读取(借助pyarrow引擎)
pandas的read_feather函数支持读取Arrow格式文件(二者格式高度兼容),只需指定engine="pyarrow":
import pandas as pd df = pd.read_feather("target_file.arrow", engine="pyarrow")
内容的提问来源于stack exchange,提问作者user2138149
相关产品推荐
相关产品推荐

