feather在小宽表上读取更快,parquet在大窄表或高压缩场景下更优,实际速度取决于数据结构、列数、压缩方式和硬件环境,需用真实数据基准测试。

pd.read_feather 和 pd.read_parquet 的实际读取速度差异,取决于数据结构、列数、压缩方式和硬件环境——不能只看“谁更快”的结论,得测你自己的数据。
用真实数据跑一次基准测试才靠谱
别信网上“Parquet > Feather”这种笼统排序。实测中,Feather 在小宽表(
推荐直接复用这段最小可行脚本:
import pandas as pd
import time
<h1>假设 df 是你的原始 DataFrame</h1><p>df.to_feather("test.feather")
df.to_parquet("test.parquet", engine="pyarrow", compression="snappy")</p><h1>分别测 3 次取中位数,避开缓存干扰</h1><p>def time<em>read(func, *args, **kwargs):
times = []
for </em> in range(3):
t0 = time.perf_counter()
func(*args, **kwargs)
times.append(time.perf_counter() - t0)
return sorted(times)[1]</p><p>t_f = time_read(pd.read_feather, "test.feather")
t_p = time_read(pd.read_parquet, "test.parquet")
print(f"feather: {t_f:.3f}s | parquet: {t_p:.3f}s")</p>
- 务必用
time.perf_counter(),不是time.time() - 测试前清空 OS 文件缓存(Linux 可执行
sync && echo 3 | sudo tee /proc/sys/vm/drop_caches) - 如果数据含大量
object类型字符串,Parquet 默认用 dictionary 编码,Feather 不做此优化——这会显著拉大读取差距
read_parquet 的 engine 参数影响极大
pd.read_parquet 默认用 "pyarrow",但如果你装了 fastparquet 并显式指定 engine="fastparquet",在某些时间序列场景下读取可能慢 2–3 倍,且不支持所有 Parquet 特性(如 nested types)。
- 99% 场景下坚持用
engine="pyarrow" - 避免混用:写用
pyarrow,读却用fastparquet,会报ArrowInvalid: Unsupported writer version - PyArrow 14+ 对 null 值处理更激进,若数据含大量 NaN,Parquet 文件体积可能比 Feather 小 40%,但读取时解压开销略增
Feather 没有 compression 参数,但 Parquet 有
pd.to_feather 不接受 compression 参数——它内部固定用 LZ4,不可调。而 pd.to_parquet 支持 "snappy"、"gzip"、"zstd" 等,压缩率和解压速度权衡明显:
-
compression="snappy":解压快,适合高频读取,文件略大 -
compression="zstd":压缩率高,但 CPU 解压耗时上升,IO 密集型任务可能反拖慢 - 别用
compression="gzip":Pandas 读取时是单线程解压,遇到大文件极易成为瓶颈
同一份数据存成 snappy 和 zstd Parquet,读取时间差可达 30%,但 Feather 始终稳定在中间值附近——这是它“省心但不够灵活”的本质。
真正容易被忽略的点:列裁剪与元数据加载
Parquet 文件自带完整 schema 和统计信息(min/max),pd.read_parquet 能跳过整行/整块——比如加 filters=[("col_a", ">", 100)],底层直接跳过不满足条件的 row group。Feather 没有这个能力,usecols 只能跳过列,不能跳过行。
- 如果你常做子集查询(如“只读 status=active 的用户”),Parquet 的 filter 下推是硬优势
- Feather 的
usecols有效,但仅限于列名列表;传入列索引会报错:TypeError: usecols must be a list of strings - Parquet 元数据本身要加载,首次读取小文件(
格式选型不是只比“谁读得快”,而是比“谁在你的访问模式下最不拖后腿”。Feather 简单粗暴,Parquet 精密但有门槛——尤其当团队里有人误删了 Parquet 文件的 footer,整个文件就废了,而 Feather 没 footer 可删。
Python免费学习笔记(深入):立即使用
在学习笔记中,你将探索 Python 的核心概念和高级技巧!











