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 ?
Asked
Active
Viewed 2.9k times
15
-
4[`read_excel`](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html#pandas.read_excel) the `sheetname` param defaults to `0` which is the first sheet – EdChum May 27 '15 at 09:13
-
even if there are multiple sheets it selects the first one ? – Meghdeep Ray May 27 '15 at 09:15
-
1Yes, why don't you try it – EdChum May 27 '15 at 09:15
3 Answers
28
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

HarshaYerasi
- 23
- 4

Meghdeep Ray
- 5,262
- 4
- 34
- 58
2
Also this bug at the time of writing: https://github.com/pandas-dev/pandas/issues/17107
Use 'sheetname', not 'sheet_name'.

StinkySocks
- 812
- 1
- 13
- 20
0
Following the official documentation and as already suggested by EdChum, it's enough to use read_excell passing sheetname=N as argument. N=0 for the first sheet, N=1 for the second, N=2 for the third and so on..

alec_djinn
- 10,104
- 8
- 46
- 71
-
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 – Ben May 30 '18 at 17:18