Use DataFrame.to_excel() to save a DataFrame to an Excel workbook. For a new workbook, df.to_excel("output.xlsx", index=False) writes the columns without the row index. Use ExcelWriter when you need multiple sheets or want to append to an existing workbook.
Write one DataFrame to a new Excel file
Here is a complete minimal example:
import pandas as pd
df = pd.DataFrame({"name": ["Ada", "Grace"], "score": [98, 95]})
df.to_excel("output.xlsx", index=False)
The path can be a path-like object or a file-like target. If you omit sheet_name, pandas uses Sheet1. The default is index=True, which writes row-index labels as an additional column; pass index=False when those labels are not part of the output. See the DataFrame.to_excel API and the official getting-started tutorial.
Choose what appears in the worksheet
to_excel() provides controls for columns, headings, missing values, and placement. For example:
df.to_excel(
"output.xlsx",
sheet_name="Results",
columns=["name", "score"],
header=["Employee", "Points"],
index=False,
na_rep="(missing)",
float_format="%.2f",
freeze_panes=(1, 0),
autofilter=True,
)
sheet_namenames the worksheet;columnsselects which DataFrame columns to write.headercontrols or renames column headings. Useindex_labelto label index columns when you keep the index.na_repsets the text used for missing values, andfloat_formatcontrols floating-point representation.startrowandstartcolplace the output at a chosen worksheet position.freeze_panesandautofilteradd common worksheet conveniences.- For a MultiIndex,
merge_cellscontrols whether labels are merged. Lists and dictionaries are written as strings; Excel has no native infinity value, soinf_repcontrols how infinity is represented.
Check the API reference for supported arguments and details for your pandas version.
Recommended Free Tools
#1 Best Overall
Write multiple DataFrames to separate sheets
Open one ExcelWriter and pass it to each DataFrame’s to_excel() call. Using it as a context manager saves the workbook and closes file handles when the block ends:
with pd.ExcelWriter("output.xlsx") as writer:
df_a.to_excel(writer, sheet_name="Summary", index=False)
df_b.to_excel(writer, sheet_name="Details", index=False)
Do all the writes before the writer closes. After a workbook has been saved, another to_excel() call cannot add data to it without rewriting the workbook, as the pandas API notes. If you do not use a context manager, close the writer explicitly. The same writer interface can target an in-memory buffer such as BytesIO. See the ExcelWriter reference.
Append a sheet to an existing workbook
To preserve an existing workbook and add a worksheet, use append mode with the openpyxl engine. Decide explicitly what should happen if the target sheet already exists:
with pd.ExcelWriter(
"existing.xlsx",
mode="a",
engine="openpyxl",
if_sheet_exists="replace",
) as writer:
df.to_excel(writer, sheet_name="Results", index=False)
| Existing-sheet policy | Effect | Use it when |
|---|---|---|
replace |
Replace the contents of the matching sheet. | You want the named sheet rebuilt from the DataFrame. |
overlay |
Write over or alongside existing worksheet content without replacing the sheet itself. | You are deliberately placing output into an existing sheet and have chosen safe starting cells. |
With overlay, set startrow or startcol where needed and check for overlapping cells; otherwise new output can collide with existing data. These append options are documented in the ExcelWriter reference.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Rank #3
Use an explicit path and mode whenever existing data matters. A writer opened in the default write mode overwrites an existing file with that name. For a new workbook, confirm the destination is safe before running the code.
Select an engine and file format
Writer engines are optional dependencies, and the default can depend on installed packages and pandas configuration. The current ExcelWriter reference specifies XlsxWriter for .xlsx when it is installed and otherwise openpyxl. The pandas Excel I/O guide describes openpyxl for .xlsx and .xlsm, XlsxWriter for .xlsx, and odf for .ods.
Rank #4
- Crisp writing pages are perfect for personal reflections, sketching, or for recording favorite quotations or poems.
- Premium 120 gsm paper takes pen or pencil beautifully.
- Paper is acid free and of archival quality.
- Light gray lines subtly guide your writing.
- An inside back cover pocket expands to hold notes, cards, mementos, and more.
For a predictable engine or engine-specific capabilities, select it explicitly and install the corresponding optional dependency:
with pd.ExcelWriter("output.xlsx", engine="xlsxwriter") as writer:
df.to_excel(writer, sheet_name="Data", index=False)
Engine choice also affects workbook features and formatting options. The guide links to XlsxWriter’s pandas integration for engine-specific formatting workflows.
Best Value
- Funny design. Import pandas as pd, an all too familiar python code.
- Featuring a familiar python code, this will get a laugh from all the nearby programmers and GIS professionals.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
Style output and check workbook limits
As of pandas 3.0, to_excel() does not apply default styling. For styled output, use Styler.to_excel() or engine-specific formatting options described in the Excel I/O guide.
pandas checks Excel’s row, column, and cell-character limits, but the API documentation says other Excel limitations remain the user’s responsibility. Validate the workbook against the constraints of the application and workflow that will consume it.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




