I wrote a program that uses a data frame to write to an excel workbook using pandas. would there be a better way to save the workbook? When I tried to use the built in methods I get an error message “ValueError: I/O operation on closed file”.
My original solution involved opening the workbook after writing to it however when opening it I often get an error stating “your file wasn’t update because we cannot apply changes made by someone else using an older version of excel”
Here is my code
with pd.ExcelWriter(path , mode="a" , engine="openpyxl" , if_sheet_exists="replace") as writer:
df.to_excel(writer, sheet_name="Sheet1")
#writer.close()
driver.close()
time.sleep(3)
os.system('start EXCEL.EXE "path of my file"')
the writer.close() line is my attempt at using the close() function which should save the file as well without opening it. Any help appreciated
Like stated above, I have tried saving the file a few different ways however none of them consistently work or flat out don’t work at all. Opening the excel sheet after worked for awhile until recently I started getting the error saying excel couldn’t merge.
user25721522 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.