如何使用熊猫编辑XLSX电子表格
如何使用熊猫或任何其他库编辑电子表格.
How do I edit spreadsheets using pandas, or any other library.
我有一个CSV,用于读取数据和一些过滤器,准备将其保存在XLSX工作表中.
I have a CSV where I do the data reading and some filters, which I intend to save in an XLSX worksheet ready.
但是,当我尝试将数据帧发送到此XLSX工作表时,该文件会通过删除工作表中所有现有的编辑和工作表而被覆盖.
But when I try to send the dataframe to this XLSX worksheet, the file is overwritten by removing all existing edits and sheets in the worksheet.
我正在尝试这样做.
excel_name = 'data/nessus/My Scans/Janeiro_2019/teste.xlsx'
writer = pd.ExcelWriter(excel_name, engine='xlsxwriter')
df5.to_excel(writer, sheet_name='FullExport', index=False)
workbook=writer.book
worksheet = writer.sheets['FullExport']
writer.save()
我认为我做错了,但我无法解决.
I think I'm doing something wrong, but I can not solve it.
PS:
此数据框应发送到第2行上名为"FullExport"的工作表
This dataframe should be sent to the sheet called "FullExport" on line 2
在熊猫版本0.24
中,它们将是mode='a'
的选项;然而;现在,您将必须:
In pandas version 0.24
they will be an option for mode='a'
; however; right now you will have to:
writer = pd.ExcelWriter(excel_name, engine='openpyxl')
writer.book = load_workbook(excel_name)
df5.to_excel(writer, sheet_name='FullExport', index=False)
writer.save()
write.close() # i think close() already runs the save function above