I have a dataframe called results and an excel file named as vlpandas.xlsx. I set a default path for working dir as follows: excel_dir = 'Users/Documents/Pythonfiles'
Based on the example from this post,: How to save a new sheet in an existing excel file, using Pandas?, I did the following:
book = load_workbook(excel_dir)
But I an error above after running the command, to fix it I use the usage as documented from the openpyxl and the following works:
book = load_workbook(filename = 'vlpandas.xlsx')
But then I get an exception error when I run the command below. Something about workbook.py from the openpyxl directory.
writer = pd.ExcelWriter(excel_dir, engine='openpyxl')
and then I want to complete my task saving the data to the new worksheet in the existing file vlpandas.xlsx with the following lines of code:
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
## Your dataframe to append.
results.to_excel(writer, '3rd_sheet')
writer.save()
So my two questions are:
1) What is the proper usage of load_Workbook from openpyxl 2) Why I am I getting an error with the command line below. I also changed my working folder path using the command osc.chdir:
writer = pd.ExcelWriter(excel_dir, engine='openpyxl')
Regards, Gus