0

Closely related to this question but a little bit different.

I open an excel file with openpyxl, which works fine.

import pandas as pd
from openpyxl import Workbook, load_workbook
file_name = 'Excel_File.xlsx'

Then I define a function which opens a sheet from the file and reads in data with the pandas package:

def exm_fct():
        sheet = 'sheet_name'
        read_data = pd.read_excel(file_name, sheet_name=sheet, engine='openpyxl', usecols="A:C", skiprows=1)

    return read_data

When I apply the function for the first time, everything goes right. But when I do it for the second time, I get the BadZipFile: File is not a zip file-Error and the Excel File is corrupted and I can't even open it in Excel anymore.

TOm_99
  • 25
  • 3
  • Does this question help? https://stackoverflow.com/q/57817758/11286032 – Marcelo Paco Mar 27 '23 at 21:38
  • Not really, the suggested solution says that the file has to be the .xlsx format and the engine has to be specified as engine='openpyxl', which is both the case in my problem. – TOm_99 Mar 28 '23 at 07:19

0 Answers0