小编lau*_*man的帖子

为什么 Polars.scan_csv 比磁盘读取速度还要快?

我正在通过APILazyDataFramepolars.scan_csv. filter表现比我预期的要好得多。过滤 CSV 文件的速度甚至比磁盘速度还要快!为什么???

CSV 文件位于1.51 GB我的 PC 硬盘上。

测试代码:

import polars as pl
t0 = time.time()
lazy_df = pl.scan_csv("kline.csv")
df = lazy_df.filter(pl.col('ts') == '2015-01-01').collect().to_pandas()
print(time.time() - t0)

> Output: 1.8616907596588135
Run Code Online (Sandbox Code Playgroud)

扫描整个 CSV 文件所需时间少于2 seconds,这意味着扫描速度比750MB/S. 显然,它比磁盘速度快得多。

python python-3.x pandas python-polars

4
推荐指数
1
解决办法
2240
查看次数

标签 统计

pandas ×1

python ×1

python-3.x ×1

python-polars ×1