我有一些代码可以将pandas数据框写入Excel工作表,由于某种原因,它什么也没做。我以前成功使用过相同的方法。
book = load_workbook(os.path.commonpath(output)) #user is prompted for output file earlier in program
writer = pd.ExcelWriter(os.path.commonpath(output), engine = 'openpyxl')
writer.book = book
writer.sheets = dict((ws.title, ws) for ws in book.worksheets)
df.to_excel(writer, sheet_name = 'Check', startrow = writer.sheets['Check'].max_row, index = False) # this should write the df out starting at the first row that doesn't contain any data in the excel sheet.
该程序运行正常,当我打开它时,没有输出到excel工作表。有什么想法吗?
答案 0 :(得分:1)
我相信您在代码末尾需要一个writer.save()
!