Skip to content
Advertisement

How can I export all dataframes into an Excel file

I have a notebook open with about 45 dataframes. I would like to export all of them into a single Excel file with each dataframe being it’s own tab in Excel.

Is there an easy way to do this without having to write each tab out manually?

Thank you!

Advertisement

Answer

Please check the link Example: Pandas Excel with multiple dataframes

You can then as suggested by @delimiter create a list of the names

import pandas as pd
# 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')

list = [df1,df2,df3]
names = ['df1','df2','df3']
for i in range(len(list)):
    list[i].to_excel(writer, sheet_name=names[i])
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement