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

Pandas 2.0.1调用Int64Index报AttributeError问题求助

解决Pandas 2.0.1中找不到Int64Index的问题

先确认当前环境的Pandas版本,运行以下代码检查是不是真的在使用2.0.1:

import pandas
print(pandas.__version__)

如果输出不是2.0.1,说明Jupyter没用到你安装新版本的环境,解决方法:

  • 用conda的话,先激活对应环境(比如conda activate your_env),再启动Jupyter
  • 用pip的话,执行python -m pip install pandas==2.0.1确保安装到当前Python环境,再用python -m notebook启动Jupyter

如果版本确实是2.0.1,那是因为Pandas 2.0+不再把Int64Index放在顶级命名空间下了,换两种方式使用:

  • 直接从子模块导入:
from pandas.core.indexes.numeric import Int64Index
# 正常使用示例
idx = Int64Index([1, 2, 3])
  • 官方推荐写法,通过Index指定dtype:
# 普通整数索引
idx = pandas.Index([1, 2, 3], dtype='int64')
# 可空整数索引(支持None值)
idx = pandas.Index([1, 2, None], dtype='Int64')

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 07:07:03