简体   繁体   English

如何使用熊猫编辑XLSX电子表格

[英]How do I edit XLSX spreadsheets with pandas

How do I edit spreadsheets using pandas, or any other library. 如何使用熊猫或任何其他库编辑电子表格。

I have a CSV where I do the data reading and some filters, which I intend to save in an XLSX worksheet ready. 我有一个CSV,用于读取数据和一些过滤器,准备将其保存在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. 但是,当我尝试将数据帧发送到此XLSX工作表时,该文件将通过删除工作表中所有现有的编辑和工作表而被覆盖。

I'm trying to do so. 我正在尝试这样做。

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: PS:

This dataframe should be sent to the sheet called "FullExport" on line 2 此数据帧应发送到第2行上名为“ FullExport”的工作表

In pandas version 0.24 they will be an option for mode='a' ; 在熊猫0.24版本中,它们将成为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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将我使用 Pandas (python) 创建的 .xlsx 文件保存到不同的文件位置? - How do I get my .xlsx file I created using Pandas (python) to save to a different file location? 如何在 Pandas DataFrame 中编辑 Tensorflow 数据集? - How do I edit a Tensorflow dataset in a Pandas DataFrame? 如何使用 pandas 编辑 a.CSV 中的特定列或行? - How do I Edit A Certain Column or Row in a .CSV using pandas? 如何使用 Pandas 遍历 xlsx 工作表并仅读取某些列? - How do I use Pandas to iterate through an xlsx sheet and only read certain columns? 如何使用 Pandas 将我的数据导入到 xlsx 文件中的表中? - How do I import my data into a table in an xlsx file using Pandas? 如何制作从大型 xlsx 文件加载 pandas DataFrame 的进度条? - How do I make a progress bar for loading pandas DataFrame from a large xlsx file? 将熊猫df写入xlsx时,如何使此循环正常工作? - How do I get this loop to work correctly when writing pandas df to xlsx? 如何编辑特定 xlsx 列中的文本? - How can I edit text in a specific xlsx column? 如何将此 xlsx 转换为 Python 中的 JSON - How do I convert this xlsx to JSON in Python 将 Python 与 Google 电子表格连接时,如何修复“SpreadsheetNotFound”? - How do I fix "SpreadsheetNotFound" when interfacing Python with Google Spreadsheets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM