Pandas 无法读取特定的 Excel 工作表

Posted

技术标签:

【中文标题】Pandas 无法读取特定的 Excel 工作表【英文标题】:Pandas cannot read specific Excel sheet 【发布时间】:2018-07-26 07:22:57 【问题描述】:

似乎这已经有了here 和here 的答案,但是,这些解决方案都不适合我。

我正在努力

xls = pd.ExcelFile('input.xls')
df = pd.read_excel(xls, sheet_name="Sheet2") ## Also tried sheet_name = 1

无论如何,df 最终仍然包含第一张而不是第二张。我在 Python 3 和 Pandas 0.20.1(Anaconda 发行版)上。我错过了什么?如何将第二张工作表加载到df

【问题讨论】:

尝试使用sheetname 而不是sheet_namesheet_name 在 Pandas 0.21.0 中替换了已弃用的 sheetname 做到了!文档不正确吗? 【参考方案1】:

来自docs:

sheetname :字符串,整数,字符串/整数的混合列表,或无,默认 0

自 0.21.0 版起已弃用:改用 sheet_name

这也意味着在0.21.0版本之前它曾经是sheetname ;-)

【讨论】:

以上是关于Pandas 无法读取特定的 Excel 工作表的主要内容,如果未能解决你的问题,请参考以下文章