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'已存在且处于打开状态。此时关闭该文件后再次运行程序便可。
相关文章
相关标签/搜索