2

I am trying to read excel (.xlsx) file and convert it to dataframe. I used pandas.ExelFile , pandas.read_excel, openpyxl load_workbook and even io file reading methods but i am unable to read Sheet of this file. Every time i get list index out of range error or no sheet names is case of openpyxl. Also tried xlrd method.

temp_df = pd.read_excel("v2s.xlsx",  sheet_name = 0)

or

temp_df = pd.read_excel("v2s.xlsx",  sheet_name = "Sheet1")

or from openpyxl import load_workbook workbook = load_workbook(filename="v2s.xlsx",read_only = True, data_only = True) workbook.sheetnames

Link to excel file

4
  • try xl = pd.ExcelFile('v2s.xlsx') then print(xl.sheet_names) check to see if that sheet exists, the error looks like it doesn't exist. Commented Feb 9, 2020 at 20:06
  • xl = pd.ExcelFile("v2s.xlsx") print(xl.sheet_names) this returns [] an empty array Commented Feb 10, 2020 at 6:07
  • That answers your question the excel file is empty Commented Feb 10, 2020 at 8:29
  • @Datanovice the excel file is not empty, there is a sheet with data on it. Commented Feb 10, 2020 at 15:13

1 Answer 1

5

According to this ticket, the file is saved in a "slightly defective" format.

The user posted that he used Save As to change the type of document back to a normal Excel spreadsheet file.

Your file is this type:

Save as type

You need to save it as:

New type

Then running your code

from openpyxl import load_workbook
workbook = load_workbook(filename="v2s_0.xlsx",read_only = True, data_only = True)
print(workbook.sheetnames)

Outputs:

['Sheet1']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.