title: How to write multiple dataframes into multiple sheets in a memory and time efficient way in python?
body: <p>I have a list of <code>Dataframe</code> which I need to write to in excel file in different sheets. Currently I am using the below code -</p>
  <pre><code>dfs = [df1, df2, df3, df4]
  sheets = ['sheet1', 'sheet2', 'sheet3', 'sheet4']
  df_sheets = zip(dfs, sheets)
  
  for df, sheet_name in df_sheets:
      writer = pd.ExcelWriter('output.xlsx', engine='openpyxl', mode='a', if_sheet_exists='replace')
      writer.book = openpyxl.load_workbook('output.xlsx')
      writer.sheets = dict((ws.title, ws) for ws in writer.book.worksheets)
      df.to_excel(writer, sheet_name, index=False)
      writer.close()
  </code></pre>
  <p>Now this is taking much more time and memory. I have tried to move the <code>writer</code> initation before loop and <code>writer.close()</code> after loop. But then nothing gets written to excel file.</p>