You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为使用openpyxl引擎的pandas.read_excel传递优化参数

使用pandas.read_excel结合openpyxl引擎传递优化参数

你可以通过pandas的engine_kwargs参数,将openpyxl的专属优化参数传递给read_excel方法,具体实现如下:

完整代码示例

import pandas as pd

# 封装openpyxl的优化参数
openpyxl_settings = {
    "read_only": True,
    "data_only": True,
    "keep_links": False
}

# 读取目标Excel文件
df = pd.read_excel(
    "你的文件路径.xlsx",
    engine="openpyxl",
    engine_kwargs=openpyxl_settings
)

参数说明

  • engine="openpyxl":明确指定pandas使用openpyxl作为Excel读取引擎(需提前安装openpyxl:pip install openpyxl)
  • engine_kwargs:该参数专门用于传递指定引擎的初始化参数,这里的字典会直接传递给openpyxl的工作簿构造函数
  • 各openpyxl参数作用:
    • read_only=True:以只读模式加载文件,大幅降低大文件的内存占用
    • data_only=True:仅读取单元格的计算结果,而非原始公式
    • keep_links=False:跳过Excel中的链接对象,加快加载速度并避免潜在的链接解析问题

内容的提问来源于stack exchange,提问作者bzm3r

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 03:42:02