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

Pandas读取Excel报错:'ElementTree'对象无'getiterator'属性求助

Fixing AttributeError When Reading Excel with Pandas in Python 3.9+

Hey there! Let's break down why you're hitting this error and fix it step by step.

What's Causing the Issue?

The AttributeError: 'ElementTree' object has no attribute 'getiterator' pops up for two key reasons:

  • You’re using Python 3.9 or newer, where the xml.etree.ElementTree.ElementTree class removed the deprecated getiterator() method.
  • Your installed version of xlrd is outdated and still relies on this removed method. On top of that, xlrd 2.0.0 and later no longer support .xlsx files—they only work with older .xls formats.

Since you already have openpyxl installed, just specify it as the engine in pd.read_excel(). This is the most reliable fix for .xlsx files:

import pandas as pd
filepath = r'/Users/vignesh/Desktop/Python/test2.xlsx'
df = pd.read_excel(filepath, engine='openpyxl')
print(df)

Solution 2: Double-Check File Path & Dependencies

Make sure these details are correct to avoid other hiccups:

  • Verify your file path: In your error trace, you called pd.read_excel('test2.xlsx') (relative path) but your code uses an absolute path. Ensure the file exists in the location you’re referencing.
  • Update openpyxl to the latest version: Run this command in your terminal to confirm:
    pip install --upgrade openpyxl
    

Bonus: For .xls Files (If Applicable)

If your file was an older .xls format, you could install a Python 3.9-compatible version of xlrd that supports .xls:

pip install xlrd==1.2.0

But skip this if you’re working with .xlsx—stick with Solution 1 instead.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.09 19:58:14