我收到一个“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)
答案 0 :(得分:1)
Python应该为您提供在回溯中找到错误的行号。在这种情况下,错误出现在for
循环中:
for sheet in book.sheets():
...
请注意sheet
和in
之间的空格。