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()