Questions tagged «xlsxwriter»

9
如何使用Pandas将新工作表保存在现有的Excel文件中?
我想使用Excel文件来存储用python制作的数据。我的问题是我无法将图纸添加到现有的excel文件中。在这里,我建议使用示例代码来解决此问题 import pandas as pd import numpy as np path = r"C:\Users\fedel\Desktop\excelData\PhD_data.xlsx" x1 = np.random.randn(100, 2) df1 = pd.DataFrame(x1) x2 = np.random.randn(100, 2) df2 = pd.DataFrame(x2) writer = pd.ExcelWriter(path, engine = 'xlsxwriter') df1.to_excel(writer, sheet_name = 'x1') df2.to_excel(writer, sheet_name = 'x2') writer.save() writer.close() 此代码将两个DataFrame保存到两个表中,分别命名为“ x1”和“ x2”。如果创建两个新的DataFrame并尝试使用相同的代码添加两个新的工作表“ x3”和“ x4”,则原始数据将丢失。 import pandas as …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.