duckdb excel插件和rusty_sheet插件在python中的不同表现

  1. 建立虚拟环境
    安装python扩展包duckdb、polars和pandas

    python -m venv pwin313
    pwin313\scripts\activate.bat
    pwin313)C:\d\pwin313>pip install duckdb polars pandas

  2. 在python中引入扩展包,安装加载duckdb插件

    pwin313) C:\d\pwin313>python
    Python 3.13.2 (tags/v3.13.2:4f8bb39, Feb 4 2025, 15:23:48) [MSC v.1942 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.

    import duckdb
    duckdb.sql("install excel")
    duckdb.sql("install rusty_sheet from community")
    import time

    duckdb.sql("load excel")
    duckdb.sql("load rusty_sheet")

rusty_sheet是 v0.4.2版。

分别测试两种插件不转成数据框和转成polars、duckdb数据框

复制代码
>>> t=time.time();duckdb.sql("select * from read_xlsx('/d/lineitem.xlsx')");t1=time.time();print(t1-t)
0.3100736141204834
>>> t=time.time();duckdb.sql("select * from read_xlsx('/d/lineitem.xlsx')").pl();t1=time.time();print(t1-t)
4.7497313022613525
>>> t=time.time();duckdb.sql("select * from read_xlsx('/d/lineitem.xlsx')").fetchdf();t1=time.time();print(t1-t)
4.8916003704071045


>>> t=time.time();duckdb.sql("select * from read_sheet('/d/lineitem.xlsx',range='2:')");t1=time.time();print(t1-t)
4.251304626464844
>>> t=time.time();duckdb.sql("select * from read_sheet('/d/lineitem.xlsx',range='2:')").pl();t1=time.time();print(t1-t)
9.083962440490723
>>> t=time.time();duckdb.sql("select * from read_sheet('/d/lineitem.xlsx',range='2:')").fetchdf();t1=time.time();print(t1-t)
9.565066576004028

可见,read_xlsx不转数据框,则不实际读取数据,而read_sheet读取。

相关推荐
Warson_L1 小时前
Python `Annotated` 与 LangGraph Reducer 学习笔记
python
韩师傅1 小时前
海天线算法的前世今生
python·计算机视觉
韩师傅1 小时前
当你的甲方设备过烂,要如何快速出效果?
python·计算机视觉
Warson_L1 小时前
LangGraph的MessageState and HumanMessage
python
韩师傅2 小时前
当你的甲方吐槽天空不够蓝,你应该如何应对
python·计算机视觉
Warson_L3 小时前
python的类&继承
python
Warson_L3 小时前
类型标注/type annotation
python
ThreeS5 小时前
手搓MiniVLA全实战教程-一步一步用pytorch解释原理与思路
人工智能·python
金銀銅鐵6 小时前
[Python] 模 n 乘法的逆元计算器
python·数学·游戏