Pandas: Always selecting the first sheet/tab in an Excel Sheet

19,374

Solution 1

The first sheet is automatically selected when the Excel table is read into a dataframe.

To be explicit however, the command is :

import pandas as pd
fd = 'file path'
data = pd.read_excel( fd, sheet_name=0 )

Use of 'sheetname' is deprecated. Please use sheet_name

Solution 2

Also this bug at the time of writing: https://github.com/pandas-dev/pandas/issues/17107

Use 'sheetname', not 'sheet_name'.

Share:
19,374

Related videos on Youtube

Meghdeep Ray
Author by

Meghdeep Ray

Loved programming ever since I started at the age of 10. Love Python3, passionate about Artificial Intelligence, Machine Learning and Big Data Analytics. Completed my Undergraduate Degree in Computer Science and Engineering from PES University, Bangalore.

Updated on July 05, 2022

Comments

  • Meghdeep Ray
    Meghdeep Ray almost 2 years

    I know how to get the list of sheet names. The excel file I am using has multiple sheets. How do I select the first one sequentially ? I don't know the name of the sheet but I need to select the first one. How would I go about this ?

    • EdChum
      EdChum almost 9 years
      read_excel the sheetname param defaults to 0 which is the first sheet
    • EdChum
      EdChum almost 9 years
      Yes, why don't you try it
  • Ben
    Ben almost 6 years
    You don't even need to pass the sheet name, you can simply leave out the sheetname or sheet_name (the former is depreciated as of this writing) and it will take the first
  • Erick
    Erick about 4 years
    Thanks @RGH !!! I was going crazy not knowing what I was doing wrong..