我在熊猫中使用ExcelWriter
将数据写入电子表格中的不同选项卡,如下所示:
import pandas as pd
writer = pd.ExcelWriter('/path/to/file/excel_test.xlsx')
df.to_excel(writer,'tab1')
df.to_excel(writer, 'tab2')
writer.save()
只有当文件excel_test.xlsx
存在时,此代码才能工作。
如何强制ExcelWriter
检查文件是否存在,如果它不存在,则创建一个新文件?
发布于 2019-12-10 15:28:52
你可以试试:
import os
exists = os.path.isfile('/path/to/file')
if not exists:
# write file
https://stackoverflow.com/questions/59270319
复制相似问题