VOOZH about

URL: https://www.geeksforgeeks.org/python/dataframe-to_excel-method-in-pandas/

⇱ DataFrame.to_excel() method in Pandas - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

DataFrame.to_excel() method in Pandas

Last Updated : 18 Dec, 2025

DataFrame.to_excel() is a Pandas method used to export a DataFrame into an Excel file. It lets you save data to a specific file, choose the sheet name, include/exclude indexes, and write selected columns if needed. This method is helpful when you want to store processed data, share results, or create structured reports.

Example: This example shows how to export a DataFrame to an Excel file with the default settings, single sheet and index included.

Output

👁 Output
Output

Explanation: df.to_excel("data.xlsx") saves the DataFrame to an Excel file named data.xlsx in the current directory.

Syntax

DataFrame.to_excel(excel_writer, sheet_name="Sheet1", **kwargs)

Parameters:

  • excel_writer: File path or existing ExcelWriter object.
  • sheet_name: Name of the sheet to write to. Default is "Sheet1".
  • columns: Write only the selected columns.
  • index: Whether to include row index. Default True.
  • index_label: Label for index column(s).

Examples

Example 1: This example writes a DataFrame to an Excel file and customizes the sheet name.

Output

👁 Output1
Excel file created: students.xlsx with sheet MarksData

Explanation: sheet_name="MarksData" changes the sheet name from default "Sheet1".

Example 2: This example exports the DataFrame but removes the default numeric index from the Excel file.

Output

👁 Output2
Excel file created without index column.

Explanation: index=False prevents the index column from being written to the file.

Example 3: This example shows how to save multiple DataFrames into different sheets of the same Excel file using ExcelWriter.

Output: Sheet A

👁 SheetA
Sheet A

Sheet B:

👁 Screenshot-2025-12-12-170037
Sheet B

Explanation:

  • pd.ExcelWriter("multi_sheet.xlsx") allows writing multiple sheets into one file.
  • df1.to_excel(writer, sheet_name="SheetA") writes the first sheet.
  • df2.to_excel(writer, sheet_name="SheetB") writes the second sheet.
Comment