pandas 1.4.2

NotesParametersBackRef
to_excel(self, excel_writer, sheet_name: 'str' = 'Sheet1', na_rep: 'str' = '', float_format: 'str | None' = None, columns=None, header=True, index=True, index_label=None, startrow=0, startcol=0, engine=None, merge_cells=True, encoding=None, inf_rep='inf', verbose=True, freeze_panes=None, storage_options: 'StorageOptions' = None) -> 'None'

To write a single object to an Excel .xlsx file it is only necessary to specify a target file name. To write to multiple sheets it is necessary to create an ExcelWriter object with a target file name, and specify a sheet in the file to write to.

Multiple sheets may be written to by specifying unique sheet_name . With all data written to the file it is necessary to save the changes. Note that creating an ExcelWriter object with a file name that already exists will result in the contents of the existing file being erased.

Notes

For compatibility with ~DataFrame.to_csv , to_excel serializes lists and dicts to strings before writing.

Once a workbook has been saved it is not possible to write further data without rewriting the whole workbook.

Parameters

excel_writer : path-like, file-like, or ExcelWriter object

File path or existing ExcelWriter.

sheet_name : str, default 'Sheet1'

Name of sheet which will contain DataFrame.

na_rep : str, default ''

Missing data representation.

float_format : str, optional

Format string for floating point numbers. For example float_format="%.2f" will format 0.1234 to 0.12.

columns : sequence or list of str, optional

Columns to write.

header : bool or list of str, default True

Write out the column names. If a list of string is given it is assumed to be aliases for the column names.

index : bool, default True

Write row names (index).

index_label : str or sequence, optional

Column label for index column(s) if desired. If not specified, and :None:None:`header` and :None:None:`index` are True, then the index names are used. A sequence should be given if the DataFrame uses MultiIndex.

startrow : int, default 0

Upper left cell row to dump data frame.

startcol : int, default 0

Upper left cell column to dump data frame.

engine : str, optional

Write engine to use, 'openpyxl' or 'xlsxwriter'. You can also set this via the options io.excel.xlsx.writer , io.excel.xls.writer , and io.excel.xlsm.writer .

deprecated

As the :None:None:`xlwt <https://pypi.org/project/xlwt/>` package is no longer maintained, the xlwt engine will be removed in a future version of pandas.

merge_cells : bool, default True

Write MultiIndex and Hierarchical Rows as merged cells.

encoding : str, optional

Encoding of the resulting excel file. Only necessary for xlwt, other writers support unicode natively.

inf_rep : str, default 'inf'

Representation for infinity (there is no native representation for infinity in Excel).

verbose : bool, default True

Display more information in the error logs.

freeze_panes : tuple of int (length 2), optional

Specifies the one-based bottommost row and rightmost column that is to be frozen.

storage_options : dict, optional

Extra options that make sense for a particular storage connection, e.g. host, port, username, password, etc. For HTTP(S) URLs the key-value pairs are forwarded to urllib as header options. For other URLs (e.g. starting with "s3://", and "gcs://") the key-value pairs are forwarded to fsspec . Please see fsspec and urllib for more details.

versionadded

Write object to an Excel sheet.

See Also

ExcelWriter

Class for writing DataFrame objects into excel sheets.

read_csv

Read a comma-separated values (csv) file into DataFrame.

read_excel

Read an Excel file into a pandas DataFrame.

to_csv

Write DataFrame to a comma-separated values (csv) file.

Examples

Create, write to and save a workbook:

This example is valid syntax, but we were not able to check execution
>>> df1 = pd.DataFrame([['a', 'b'], ['c', 'd']],
...  index=['row 1', 'row 2'],
...  columns=['col 1', 'col 2'])
... df1.to_excel("output.xlsx") # doctest: +SKIP

To specify the sheet name:

This example is valid syntax, but we were not able to check execution
>>> df1.to_excel("output.xlsx",
...  sheet_name='Sheet_name_1') # doctest: +SKIP

If you wish to write to more than one sheet in the workbook, it is necessary to specify an ExcelWriter object:

This example is valid syntax, but we were not able to check execution
>>> df2 = df1.copy()
... with pd.ExcelWriter('output.xlsx') as writer: # doctest: +SKIP
...  df1.to_excel(writer, sheet_name='Sheet_name_1')
...  df2.to_excel(writer, sheet_name='Sheet_name_2')

ExcelWriter can also be used to append to an existing Excel file:

This example is valid syntax, but we were not able to check execution
>>> with pd.ExcelWriter('output.xlsx',
...  mode='a') as writer: # doctest: +SKIP
...  df.to_excel(writer, sheet_name='Sheet_name_3')

To set the library that is used to write the Excel file, you can pass the :None:None:`engine` keyword (the default engine is automatically chosen depending on the file extension):

This example is valid syntax, but we were not able to check execution
>>> df1.to_excel('output1.xlsx', engine='xlsxwriter')  # doctest: +SKIP
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.generic.NDFrame.to_csv

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/generic.py#2190
type: <class 'function'>
Commit: