3

The input is a list of dataframes. How can I save it into an ExcelLocalDataSet where each dataframe is a separate sheet?

James Wong
  • 35
  • 1
  • 6
  • I suppose if saving into multiple sheets is not supported, so is the case with reading multiple sheet. – Srikiran Aug 07 '20 at 00:07

1 Answers1

1

Currently the ExcelLocalDataset implementation is currently geared towards writing one sheet and this presents two possible actions for you:

  1. The ExcelLocalDataset uses XlsxWriter. You could extend or transform ExcelLocalDataset to iterate over a list of DataFrames and write the sheets, getting inspiration from the example below:
# Create some Pandas dataframes from some data.
df1 = pd.DataFrame({'Data': [11, 12, 13, 14]})
df2 = pd.DataFrame({'Data': [21, 22, 23, 24]})
df3 = pd.DataFrame({'Data': [31, 32, 33, 34]})

# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter('pandas_multiple.xlsx', engine='xlsxwriter')

# Write each dataframe to a different worksheet.
df1.to_excel(writer, sheet_name='Sheet1')
df2.to_excel(writer, sheet_name='Sheet2')
df3.to_excel(writer, sheet_name='Sheet3')

# Close the Pandas Excel writer and output the Excel file.
writer.save()

Sourced from here

  1. If your use case uses data that's the same but just split across the different sheets that then you may want to check out using the natively supported PartitionedDataSet in combination with the ExcelLocalDataSet. The PartitionedDataSet can recursively load all or specific files from a given location.