How to Write Pandas DataFrames to Multiple Excel Sheets?
Last Updated :
18 Jun, 2025
Writing multiple Pandas DataFrames to different sheets in an Excel file is a common task when organizing structured data. For example, if you have separate datasets like sales reports, inventory logs and customer feedback, you might want each to appear on a different sheet within a single Excel file (e.g., Sales, Inventory, Feedback). Let’s explore different methods to perform this efficiently using Python.
Using ExcelWriter
This is the standard and simplest way to write multiple DataFrames to different sheets in a single Excel file. You open an ExcelWriter, write each DataFrame with a specific sheet name, and save. Ideal for generating organized multi-sheet reports.
Example 1: In this example, we create three separate DataFrames, one for fruits, one for vegetables and one for baked items and write each of them to a different sheet in the same Excel file.
Python
import pandas as pd
df1 = pd.DataFrame({
'Fruits': ['Apple', 'Banana', 'Mango', 'Dragon Fruit', 'Musk Melon', 'Grapes'],
'Sales (kg)': [20, 30, 15, 10, 50, 40]
})
df2 = pd.DataFrame({
'Vegetables': ['Tomato', 'Onion', 'Ladies Finger', 'Beans', 'Beetroot', 'Carrot'],
'Sales (kg)': [200, 310, 115, 110, 55, 45]
})
df3 = pd.DataFrame({
'Baked Items': ['Cakes', 'Biscuits', 'Muffins', 'Rusk', 'Puffs', 'Cupcakes'],
'Sales (kg)': [120, 130, 159, 310, 150, 140]
})
with pd.ExcelWriter("sales_report.xlsx") as writer:
df1.to_excel(writer, sheet_name="Fruits", index=False)
df2.to_excel(writer, sheet_name="Vegetables", index=False)
df3.to_excel(writer, sheet_name="Baked Items", index=False)
Output
Multi-Sheet (sales_report.xlsx file)Explanation: pd.ExcelWriter() as a context manager open a writer object. Then, we write each DataFrame to a specific sheet using .to_excel(), specifying a unique sheet_name. Setting index=False excludes the DataFrame index column from being written to the Excel file.
Example 2: In this example, we create a simple DataFrame containing product data and append it as a new sheet to an existing Excel file without modifying the current sheets.
Python
import pandas as pd
df = pd.DataFrame({
'Product': ['Marker', 'Board'],
'Qty': [10, 5]
})
with pd.ExcelWriter('existing_file.xlsx', mode='a', engine='openpyxl', if_sheet_exists='new') as writer:
df.to_excel(writer, sheet_name='NewSheet', index=False)
Output
Initial Sheet (existing_file.xlsx)
Appended Sheet (existing_file.xlsx)Explanation: We use mode='a' to append and engine='openpyxl' to ensure compatibility with .xlsx files. The if_sheet_exists='new' ensures a new sheet is added instead of overwriting an existing one.
Using openyxl
openpyxl engine is specifically designed to work with .xlsx Excel files. When combined with ExcelWriter, it allows you to modify existing Excel files such as adding new sheets, updating data or preserving existing formatting and formulas. It's essential when you need to maintain the structure of an Excel file while programmatically adding or changing content.
Initial Sheet(existing.xlsx)
Python
import pandas as pd
df = pd.DataFrame({'Drinks': ['Coke', 'Pepsi'], 'Qty': [50, 60]})
with pd.ExcelWriter('existing.xlsx', engine='openpyxl', mode='a') as writer:
df.to_excel(writer, sheet_name='CoolDrinks')
Output
CoolDrinks Sheet (existing.xlsx)Explanation: This example shows how to open an existing .xlsx file and append a new sheet named CoolDrinks without affecting existing content.
Using ZipFile Module
This method helps save Excel files inside a .zip archive using Python’s built-in zipfile module. It’s particularly useful when dealing with large files. You create the Excel content in memory using a buffer and then compress it directly saving space and making file transfers faster.
Python
import pandas as pd
import zipfile
df1 = pd.DataFrame({'Fruits': ['Apple', 'Banana'], 'Qty': [10, 15]})
df2 = pd.DataFrame({'Drinks': ['Coke', 'Pepsi'], 'Qty': [25, 30]})
with zipfile.ZipFile("compressed_output.zip", "w") as zf:
with zf.open("report.xlsx", "w") as buffer:
with pd.ExcelWriter(buffer, engine='xlsxwriter') as writer:
df1.to_excel(writer, sheet_name='Fruits', index=False)
df2.to_excel(writer, sheet_name='Drinks', index=False)
Output
Zipped Excel
report.xlsx File Explanation: Here, we use zipfile.ZipFile to create a zip archive and write an Excel file directly into it. xlsxwriter is used to generate the Excel file in memory and buffer serves as an in-memory stream for writing.
Similar Reads
How to Stack Multiple Pandas DataFrames? In this article, we will see how to stack Multiple Pandas Dataframe. Stacking means appending the dataframe rows to the second dataframe and so on. If there are 4 dataframes, then after stacking the result will be a single dataframe with an order of dataframe1,dataframe2,dataframe3,dataframe4. Panda
6 min read
How to Write Data to Excel Spreadsheets in MATLAB? MATLAB provides options to write a table, array, or matrix to Microsoft Excel spreadsheets. The function available to do so is the writetable () function. The general syntax for this function is: Syntax: writetable(<data>, <filename>, <optional_values>) Now, in the following sectio
3 min read
Export Dataframes to Multiple Excel Sheets in R An excel workbook is used to contain tabular information stored within a cell-like structure. Every excel workbook in R contains multiple sheets to contain the data belonging to the same domain information. The excel sheet can contain columns belonging to different data types. The Excel files can be
5 min read
How to Plot Multiple Series from a Pandas DataFrame? In this article, we will discuss how to plot multiple series from a dataframe in pandas. Series is the range of the data  that include integer points we cab plot in pandas dataframe by using plot() function Syntax: matplotlib.pyplot(dataframe['column_name']) We can place n number of series and we ha
2 min read
How to Create Multiple Sheets in Excel workbook Using R In this article, we will discuss how to create multiple sheets in an excel file using the xlsx package. As we all know in general an excel file might contain one or more than one sheet present in it. Manually we can create and insert data into multiple sheets in Excel GUI Application but when it co
2 min read