Exception: Exception caught in workbook destructor. Explicit close() may be required for workbook. 錯

# 寫入表格
writer = pd.ExcelWriter('data.xlsx')
new_df.to_excel(writer, sheet_name='sheet', index=True)

在用pandas對excel進行寫入操做時,有時會報錯:ui

Exception: Exception caught in workbook destructor. Explicit close() may be required for workbook.
通常是由如下兩種狀況引發的:
(1)writer.save()。寫完文件後要保存關閉,在程序最後加上writer.save()便可。
(2)文件'data.xlsx'已存在且處於打開狀態。此時關閉該文件後再次運行程序便可。
相關文章
相關標籤/搜索