簡體   English   中英

openpyxl不將數據幀寫入Excel工作表

[英]openpyxl not writing dataframe to excel sheet

我有一些代碼將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工作表。 有任何想法嗎?

我相信您在代碼的末尾需要一個writer.save()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM