'Pandas: ValueError: Worksheet index 0 is invalid, 0 worksheets found
Simple problem that has me completely dumbfounded. I am trying to read an Excel document with pandas but I am stuck with this error:
ValueError: Worksheet index 0 is invalid, 0 worksheets found
My code snippet works well for all but one Excel document linked below. Is this an issue with my Excel document (which definitely has sheets when I open it in Excel) or am I missing something completely obvious?
EDIT - Forgot the code. It is quite simply:
import pandas as pd
df = pd.read_excel(FOLDER + 'omx30.xlsx')
FOLDER
Is the absolute path to the folder in which the file is located.
Solution 1:[1]
It seems there indeed is a problem with my excel file. We have not been able to figure out what though. For now the path of least resistance is simply saving as a .csv in excel and using pd.read_csv
to read this instead.
Solution 2:[2]
EDIT: with the info that you have the original .csv
, re-do your cleaning and save it as a .csv
from Excel; or, if you prefer, pd.read_csv
the original, and do your cleaning from the CLI with pandas
directly.
Solution 3:[3]
Your file is saved as Strict Open XML Spreadsheet (*.xlsx)
. Because it shares the same extension, it isn't obvious that the format is different. Open the file in Excel and Save As
. If the selected option is Strict Open XML Spreadsheet (*.xlsx)
, change it to Excel Workbook (*.xlsx)
, save it and try loading it again with pandas.
Solution 4:[4]
It maybe your excel delete the first sheet of index 0, and now the actual index is > 0, but the param sheet_name of function pd.read_excel is 0, so the error raised.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ivar Eriksson |
Solution 2 | |
Solution 3 | Steven |
Solution 4 | Lewis |