FileNotFoundError: [Errno 2] 导入 Excel 文件到 pandas 时出现错误

20 浏览
0 Comments

FileNotFoundError: [Errno 2] 导入 Excel 文件到 pandas 时出现错误

这个问题已经有了答案:

使用 Pandas 对同一工作簿的多个工作表进行 pd.read_excel()

当导入 Excel 文件到 Pandas 时,我遇到了“FileNotFoundError: [Errno 2] No such file or directory: \'census_data.xlsx\'”的错误提示。我已经仔细检查了文件,但仍然出现了这个错误。

以下是我的代码:

import xlrd
book = xlrd.open_workbook('census_data.xlsx')
for sheet in book.sheets():
print (sheet.name)

admin 更改状态以发布 2023年5月21日
0
0 Comments

Python应在回溯中为您提供发现错误的行号。在这种情况下,错误在您的for循环中:\n

for sheet in book.sheets():
    ...

\n请注意sheetin之间的空格。

0