[英]Multiple data frame to single excel file(two different sheets) in python pandas
I have two dataframes processed from the database. 我有两个从数据库处理的数据帧。 I need to export those data frames into excel(libreoffice calc) in two different sheets. 我需要将这些数据框导出到excel(libreoffice calc)两个不同的工作表中。
DF1: symbol datetime value 0 MOV 06:25:02 148767 1 TBI 06:25:02 267198 2 HY 06:25:02 56232 3 KAMN 06:25:02 2247 DF2: symbol datetime value 0 MC 06:25:02 1098560 1 AIG 06:25:02 5952267 2 CHS 06:25:02 1879192 3 VRX 06:25:02 5502438
I have tried the following, 我试过以下,
print df1 wr1 = pd.ExcelWriter('/home/suresh/Desktop/20151123/symbol.ods') df1.to_excel(wr1, 'Sheet1') print df2 df2.to_excel(wr1, 'Sheet2')
Now, not able to open the excel file. 现在,无法打开excel文件。
If passing an existing ExcelWriter
object, then the sheet will be added to the existing workbook. 如果传递现有的ExcelWriter
对象,则表单将添加到现有工作簿中。 This can be used to save different DataFrames
to one workbook: 这可用于将不同的DataFrames
保存到一个工作簿:
Source - in the end of webpage. 来源 - 在网页的最后。
writer = pd.ExcelWriter('output.xlsx')
DF1.to_excel(writer,'Sheet1')
DF2.to_excel(writer,'Sheet2')
writer.save()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.