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

使用pd.read_excel时出现'numpy has no float attribute'错误如何解决?

Pandas读取Excel报错“numpy has no float attribute”的解决方法

问题场景

  • 触发错误的代码:info = pd.read_excel(path_info)
  • 环境:Python 3.11、Pandas 1.5.3
  • 异常信息:numpy has no float attribute
  • 前置尝试:使用纯文本内容的测试文件、指定返回类型为pd.DataFrame,问题仍未解决

解决步骤

1. 修复Numpy版本兼容性

Pandas 1.5.3不兼容Numpy 1.24+版本(该版本移除了numpy.float等旧别名),需安装兼容版本:

pip install "numpy<1.24" --force-reinstall

2. 强制指定文本类型读取

通过dtype参数强制所有列按文本类型加载,避免Pandas自动推断类型时调用Numpy的废弃属性:

info = pd.read_excel(path_info, dtype=str)

3. 调整Pandas或Python版本

  • Pandas 1.5.3官方仅支持Python 3.7-3.10,Python 3.11属于非兼容版本,可降级Python到3.10及以下;
  • 或升级Pandas到2.0+版本(完全支持Python 3.11):
pip install --upgrade pandas

4. 重置Excel读取引擎依赖

确保openpyxl(读取xlsx的默认引擎)版本兼容,重新安装:

pip install --upgrade openpyxl

内容的提问来源于stack exchange,提问作者Luis Henrique Bastos

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 01:36:29