pandas dataframe excel writer force rename

Solutions on MaxInterview for pandas dataframe excel writer force rename by the best coders in the world

showing results for - "pandas dataframe excel writer force rename"
Giovanni
15 Aug 2020
1import pandas
2from openpyxl import load_workbook
3
4book = load_workbook('Masterfile.xlsx')
5writer = pandas.ExcelWriter('Masterfile.xlsx', engine='openpyxl') 
6writer.book = book
7
8## ExcelWriter for some reason uses writer.sheets to access the sheet.
9## If you leave it empty it will not know that sheet Main is already there
10## and will create a new sheet.
11
12writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
13
14data_filtered.to_excel(writer, "Main", cols=['Diff1', 'Diff2'])
15
16writer.save()