-4

I am getting a "FileNotFoundError: [Errno 2] No such file or directory: 'census_data.xlsx' " when importing excel file into pandas. I double checked my file was correct but I still get this error.

Here's my code:

import xlrd

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

for sheet in book.sheets():
print (sheet.name)
CA Burns
  • 101
  • 1
  • 3
  • 11
  • `for sheet in book.sheets():` – cs95 Sep 07 '17 at 04:56
  • Since I can't close as off topic, I'll close as a dupe which explains how to do it right. Use any of the answers in the marked dupe. Honestly, it isn't hard to understand the root of the problem by reading the message the syntax error returns. – cs95 Sep 07 '17 at 04:58

1 Answers1

1

Python should give you the line number that the error was found on in tracebacks. In this case, the error is in your for loop:

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

Note the space between sheet and in.

Nelson
  • 922
  • 1
  • 9
  • 23