Add new sheet to excel using pandas

A data frame can be added as a new sheet to an existing excel sheet. For this operation, the library required is openpyxl.

You can install this library using below command in Jupyter notebook. The same command can be executed in command prompt without the exclamation character “!”.

You can add the data from multiple DataFrames, each becoming one sheet.

Below snippet loads a pre-existing excel sheet and adds two more sheets to it using two different data frames.

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!

7 thoughts on “Add new sheet to excel using pandas”

    1. Farukh Hashmi

      Hi Max,

      Please make sure the excel file is already present on your system. And you provide the correct path.
      If you can share a screenshot of your screen with error I may be able to help.

  1. When I open the excel workbook, I get a warning. We found a problem with some content in “filename” So you want us to try to recover as much as we can? if you trust the source of this workbook, click Yes. I click yes and the new worksheet appear. How can I fix this error?

  2. Why do I loose the contents of my original workbooks when I try this
    def Copy_Sheet_rename(path,pathn,Sheet,Sheetn):
    # Copy a sheet to another sheetn
    data = pd.read_excel(path, sheet_name=Sheet)
    data.to_excel(pathn, sheet_name=Sheetn)

    # Copy_Sheet_rename(path,pathNew,”Zadar_Az1″,”Zadar_Az1New”) # copy to a new workbook
    Copy_Sheet_rename(path,path,”Zadar_Az”,”Zadar_Az1New”) # copy within the same workbook

    Contents of xlsx file before
    Zadar_Az
    Zadar_Az2
    Zadar_El
    Zadar_Az3
    Zadar_El1
    Zadar_Az4
    Zadar_El2
    Zadar_Az5
    Zadar_El3
    Zadar_Az6
    Zadar_El4
    Zadar_Az7
    Zadar_El5
    Sheet1
    Zadar_Az8
    Zadar_El6
    Zadar_Az9
    Zadar_El7
    Zadar_Az10
    Zadar_El8
    Zadar_Az11
    Zadar_El9
    Contents After
    (1,)
    Zadar_Az1New

Leave a Reply!

Your email address will not be published. Required fields are marked *