I want to save a data frame to the second sheet of a file but I can't do that and I don't know why.
yfile = openpyxl.load_workbook(new_file, data_only=True)
ws = yfile.worksheets[0]
sheet2 = yfile.create_sheet()
ws2 = yfile.get_sheet_by_name("Sheet").title = "Analysis"
writer = pd.ExcelWriter(yfile, engine='xlsxwriter')
df3.to_excel(writer, sheet_name='Analysis')
writer.save()
yfile.save(new_file)
I have created the sheet 'Analysis' but when I save in it I received the following response: "AttributeError: 'Workbook' object has no attribute 'write'"
What I have to modify?
You can use such way as below. It writes dataframe to an excel-file row by row.
Use the following helper function:
NOTE: for Pandas < 0.21.0, replace
sheet_name
withsheetname
!Demo:
Result:
Sheet1:
Sheet2:
Sheet3:
PS tested using the following versions: