简体   繁体   English

python pandas中的多个数据框到单个excel文件(两个不同的工作表)

[英]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.

相关问题 使用Python 3将多个Excel工作簿和工作表导入到单个数据框中 - Using Python 3 to import multiple excel workbooks and sheets into single data frame 从特定路径(具有特定工作表名称)读取多个 excel 文件到单个 pandas 数据框中 - Reading multiple excel files from a certain path (with certain sheets names) into a single pandas data frame 使用 Python/Pandas 创建具有多张工作表的 Excel 文件 - Create an Excel file with multiple sheets with Python/Pandas 将多张 excel 文件转换为 pandas 中的单个 JSON 格式 - Convert excel file with Multiple sheets to single JSON format in pandas 在pandas中使用不同的工作表名称读取多个excel文件 - Read multiple excel file with different sheets names in pandas "使用数据框 Python pandas 创建多个 Excel 工作表" - Creating Multiple Excel sheets using data frames Python pandas 使用python pandas在excel中的多个工作表中写入数据 - Write data in multiple sheets in excel using python pandas 使用 Python 将大型 CSV 文件拆分为单个 Excel 中的多个工作表 - Splitting Large CSV file into multiple sheets in a single Excel using Python 熊猫:在单个数据框中导入多个excel文件,一个接一个地执行操作,并将输出打印在单个csv文件中 - Pandas : Import multiple excel files in a single data frame, perform operations one by one and print the output in a single csv file Python: Pandas - 来自多个 header ZBF57C906FA7D2BB856D07372E41 的整洁数据框 - Python: Pandas - tidy data frame from multiple header excel sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM