0

i m trying to add a pandas data frame to create a new sheet in an existing excel workbook. it either deletes the workbook and just saves the data frame or it just does not work and it gives me weird errors. "BadZipFile: File is not a zip file" i m not using zip files . here is my code :

import pandas

` from openpyxl import load_workbook

book = load_workbook(target)
writer = pandas.ExcelWriter(target, engine='openpyxl') 
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)

view.to_excel(writer, "FCST Aug 2022")
writer.save()
7
  • An Excel file is a zip file. Also, there are many questions here on SO dealing with this error. Commented Aug 24, 2022 at 20:56
  • none of them work Commented Aug 24, 2022 at 20:58
  • Dang, I had a sick solution to this but the question got closed while I was typing it Commented Aug 24, 2022 at 21:01
  • @smichael_44 - maybe you should post it in one of the linked threads, assuming it hasn't been suggested already in them. There are already many questions asking how to do this. No need to create yet more duplicates. Commented Aug 24, 2022 at 21:02
  • @BigBen it definitely was not posted when I was looking because I essentially had the same question a year ago, i'll take a look at some threads and see if there is anything new that I haven't seen, thank you Commented Aug 24, 2022 at 21:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.