Open In App

DataFrame.to_excel() method in Pandas

Last Updated : 18 Dec, 2025
Comments
Improve
Suggest changes
3 Likes
Like
Report

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.

Python
import pandas as pd
df = pd.DataFrame({"Name": ["A", "B"], "Score": [85, 92]})
df.to_excel("data.xlsx")

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.

Python
import pandas as pd
df = pd.DataFrame({"ID": [1, 2, 3], "Marks": [85, 91, 76]})
df.to_excel("students.xlsx", sheet_name="MarksData")

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.

Python
import pandas as pd
df = pd.DataFrame({"City": ["Delhi", "Mumbai", "Pune"], "Temp": [30, 32, 29]})
df.to_excel("city_temp.xlsx", index=False)

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.

Python
import pandas as pd

df1 = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
df2 = pd.DataFrame({"X": [10, 20], "Y": [30, 40]})

with pd.ExcelWriter("multi_sheet.xlsx") as writer:
    df1.to_excel(writer, sheet_name="SheetA")
    df2.to_excel(writer, sheet_name="SheetB")

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.

Explore