将excel文件导入pandas时,FileNotFoundError:[Errno 2]

时间:2017-09-07 04:24:11

标签: python excel pandas

我收到一个“FileNotFoundError:[Errno 2]没有这样的文件或目录:'census_data.xlsx'”将excel文件导入pandas时。我仔细检查了我的文件是否正确,但我仍然收到此错误。

这是我的代码:

import xlrd

book = xlrd.open_workbook('census_data.xlsx')

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

1 个答案:

答案 0 :(得分:1)

Python应该为您提供在回溯中找到错误的行号。在这种情况下,错误出现在for循环中:

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

请注意sheetin之间的空格。