【问题标题】:FileNotFoundError: [Errno 2] when importing excel files into pandas [duplicate]FileNotFoundError:将excel文件导入熊猫时[Errno 2] [重复]
【发布时间】:2018-02-15 16:26:49
【问题描述】:

在将 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)

【问题讨论】:

  • for sheet in book.sheets():
  • 由于我不能关闭主题,我将关闭作为一个解释如何正确执行它的骗子。使用标记的欺骗中的任何答案。老实说,通过阅读语法错误返回的消息,不难理解问题的根源。

标签: python excel pandas


【解决方案1】:

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

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

注意sheetin 之间的空格。

【讨论】:

    猜你喜欢
    • 2021-08-03
    • 2020-09-15
    • 1970-01-01
    • 2017-10-31
    • 1970-01-01
    • 2020-09-20
    • 2014-11-13
    • 1970-01-01
    • 2014-04-12
    相关资源
    最近更新 更多