I want to write the single dataframe to the same excel file. my code Updated Code:
data = []
r = ['1','2']
for i in r:
A = ['1','2','3','4','5']
B = ["A"]
C = ["abc234"]
m = list(zip(cycle(B),cycle(C), A))
data.extend(m)
df2 = pd.DataFrame(data,columns=['Av','Bv','Cv'])
book = load_workbook(filepath)
writer = pandas.ExcelWriter(filepath, engine='openpyxl')
writer.book = book
writer.sheets = {ws.title: ws for ws in book.worksheets}
for sheetname in writer.sheets:
df2.to_excel(writer, sheet_name=sheetname, startrow=writer.sheets[sheetname].max_row, index=False, header=False)
writer.save()
with openpyxl, if_sheet = it always replaces the old content. Can anyone help what I could use here. Expected Output:
Av Bv Cv
0 A abc234 1
1 A abc234 2
2 A abc234 3
3 A abc234 4
4 A abc234 5
5 A abc234 1
6 A abc234 2
7 A abc234 3
8 A abc234 4
9 A abc234 5