pandas.DataFrame.to_excel

pandas 3.1.1 · DataFrame · method

Write the receiver to an Excel sheet. Use ExcelWriter to manage multiple sheets in one workbook.

Call syntax

DataFrame.to_excel(…) Full signature
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,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
excel_writer Required
Positional or keyword
path-like, file-like, or ExcelWriter object

Provide an output workbook writer or file destination.

sheet_name Optional
Keyword only
Default 'Sheet1'
str

Choose worksheets by name or zero-based position. None requests every sheet where supported.

na_rep Optional
Keyword only
Default ''
str

Choose the text used to display missing values.

float_format Optional
Keyword only
Default None
str

Provide a format string or callable to control numeric display.

columns Optional
Keyword only
Default None
sequence or list of str

Supply column labels or control how columns are handled.

header Optional
Keyword only
Default True
bool or list of str

Define which row or rows provide column names, or control whether to write them.

index Optional
Keyword only
Default True
bool

Supply row labels or control how existing row labels are used.

index_label Optional
Keyword only
Default None
str or sequence

Choose the column heading written for row index values.

startrow Optional
Keyword only
Default 0
int

Set the zero-based first row of the written worksheet region.

startcol Optional
Keyword only
Default 0
int

Set the zero-based first column of the written worksheet region.

engine Optional
Keyword only
Default None
str

Choose the implementation that performs the operation.

merge_cells Optional
Keyword only
Default True
bool or 'columns'

Choose whether grouped header labels should occupy merged Excel cells.

inf_rep Optional
Keyword only
Default 'inf'
str

Choose the written representation for infinite numeric values.

freeze_panes Optional
Keyword only
Default None
tuple of int (length 2)

Provide the Excel pane location to keep the specified rows or columns visible.

storage_options Optional
Keyword only
Default None
dict

Pass storage-backend options such as connection settings or HTTP headers.

engine_kwargs Optional
Keyword only
Default None
dict

Pass a dictionary of options to the selected engine.

autofilter Optional
Keyword only
Default False
bool

Returns

None