Create an Excel deliverable
Save a prepared table for spreadsheet users or downstream office workflows.
Pandas · Module
Writes a DataFrame to an Excel worksheet. It supports direct file output or coordinated multi-sheet workbooks through ExcelWriter.
Call this DataFrame method with a file path or ExcelWriter to serialize tabular data into an Excel worksheet. Optional arguments control the sheet name, missing-value text, selected columns, headers, index output, placement, formatting, engine, frozen panes, and storage-related options.
DataFrame.to_excel(excel_writer, *, sheet_name='Sheet1', na_rep='', float_format=None, columns=None, header=True, index=True, index_label=None, startrow=0, startcol=0, engine=None, merge_cells=True, inf_rep='inf', freeze_panes=None, storage_options=None, engine_kwargs=None, autofilter=False)| Name | Type | Description |
|---|---|---|
excel_writer | path-like, file-like, or ExcelWriter | Path-like, file-like, or ExcelWriter object receiving the workbook. |
sheet_name | str | Worksheet name; defaults to 'Sheet1'. |
na_rep | str | Text used for missing values; defaults to ''. |
float_format | str, optional | Format string for floating-point values. |
columns | sequence or list of str, optional | Columns to export. |
header | bool or list of str | Whether to write column labels; defaults to True. |
index | bool | Whether to write row names; defaults to True. |
index_label | str or sequence, optional | Label for the index column or columns. |
startrow | int, default 0 | Starting row offset; defaults to 0. |
startcol | int, default 0 | Starting column offset; defaults to 0. |
engine | str, optional | Excel writing engine. |
merge_cells | bool, default True | Whether to merge MultiIndex cells; defaults to True. |
None
import pandas as pd
sales = pd.DataFrame({"product": ["A", "B"], "units": [3, 5]})
sales.to_excel("sales.xlsx", sheet_name="Sales", index=False)Creates an Excel workbook containing the DataFrame on a named sheet without writing the DataFrame index.
Save a prepared table for spreadsheet users or downstream office workflows.
Produce a workbook containing separate worksheets for different reports or datasets.
Place a DataFrame into a specified worksheet region with optional frozen panes and filters.
It writes a DataFrame to an Excel sheet. A simple .xlsx export only needs a destination filename; sheet_name selects the worksheet and defaults to Sheet1.
Follow-up: How would you export several worksheets? Create an ExcelWriter for the target file and call to_excel with a unique sheet_name for each DataFrame.
By default, the DataFrame index is written because index defaults to True. Set index=False when the index should not appear as an extra Excel column.
Follow-up: How can selected data be exported? Use columns to specify the sequence or list of column names to write.
The method accepts a path-like destination, a file-like object, or an ExcelWriter. Parameters such as startrow and startcol control the starting position, while freeze_panes identifies the pane boundary to freeze.
Follow-up: How would you place a report below existing worksheet content? Supply an appropriate startrow, and use startcol if horizontal offset is also required.
pandas.DataFrame.to_csvpandas.read_excelpandas.ExcelWriter