Ele
Ele

Reputation: 563

pandas reading excel results in "not a zip file"

I try to read a xlsx into a data frame:

itut_ir = pd.read_excel('C:\\Users\\Administrator\\Downloads\\reportdata.xlsx')

print(itut_ir.to_string())

I receive this:

Traceback (most recent call last): File "C:\Users\Administrator\eclipse-workspace\Reports\GOW\Report.py", line 44, in df = pd.read_excel('C:\Users\Administrator\Downloads\reportdata.xlsx')
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\excel_base.py", line 304, in read_excel io = ExcelFile(io, engine=engine) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\excel_base.py", line 824, in init self._reader = self.enginesengine File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\excel_xlrd.py", line 21, in init super().init(filepath_or_buffer) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\excel_base.py", line 353, in init self.book = self.load_workbook(filepath_or_buffer) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\excel_xlrd.py", line 36, in load_workbook return open_workbook(filepath_or_buffer) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\xlrd_init.py", line 117, in open_workbook zf = zipfile.ZipFile(filename) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\zipfile.py", line 1222, in init self._RealGetContents() File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\zipfile.py", line 1289, in _RealGetContents raise BadZipFile("File is not a zip file") zipfile.BadZipFile: File is not a zip file

does anybody have an idea? the file does not seem to be broken, I can open it with Excel.

thanks!

*** UPDATE *** the file producing the error is being downloaded from FTP. opening the original file works ... if that gives you a hint :) thanks

Upvotes: 5

Views: 20917

Answers (2)

hsc
hsc

Reputation: 1298

I encounter a similiar issue because of the excel is confidential, I changed the excel to general and then pandas can read it properly. More details can be found via OCa's comment above.

Upvotes: 0

Xenoranger
Xenoranger

Reputation: 518

I had the same issue just a little bit ago with an XLSX that I created in LibreOffice.

The solution was to check the XLSX to make sure it wasn't corrupted. In my case, loading a previous version of the XLSX file corrected the problem.

Upvotes: 3

Related Questions