Skip to content Skip to sidebar Skip to footer

Export Two Data Frames As One Excel File With Two Sheets In Pandas On Specified Location

I have two dataframe as shown below. df1: Date t_factor plan plan_score 0 2020-02-01 5 NaN 0 1 2020-02-02 23 NaN

Solution 1:

For me working specify excel file like:

import os
    
def save_xls(list_dfs, xls_path):
    with pd.ExcelWriter(xls_path) as writer:
        for n, df in enumerate(list_dfs):
            df.to_excel(writer,'sheet%s' % n)
        writer.save()

save_xls([df1, df2], 'file.xlsx')

Post a Comment for "Export Two Data Frames As One Excel File With Two Sheets In Pandas On Specified Location"