There are various options depending on the use case:
If one doesn't know the sheets names.
If the sheets name is not relevant.
If one knows the name of the sheets.
Below we will look closely at each of the options.
See the Notes section for information such as finding out the sheet names.
Option 1
If one doesn't know the sheets names
# Read all sheets in your File
df = pd.read_excel('FILENAME.xlsx', sheet_name=None)
# Prints all the sheets name in an ordered dictionary
print(df.keys())
Then, depending on the sheet one wants to read, one can pass each of them to a specific dataframe
, such as
sheet1_df = pd.read_excel('FILENAME.xlsx', sheet_name=SHEET1NAME)
sheet2_df = pd.read_excel('FILENAME.xlsx', sheet_name=SHEET2NAME)
Option 2
If the name is not relevant and all one cares about is the position of the sheet. Let's say one wants only the first sheet
# Read all sheets in your File
df = pd.read_excel('FILENAME.xlsx', sheet_name=None)
sheet1 = list(df.keys())[0]
Then, depending on the sheet name, one can pass each it to a specific dataframe
, such as
sheet1_df = pd.read_excel('FILENAME.xlsx', sheet_name=SHEET1NAME)
Option 3
Here we will consider the case where one knows the name of the sheets.
For the examples, one will consider that there are three sheets named Sheet1
, Sheet2
, and Sheet3
. The content in each is the same, and looks like this
0 1 2
0 85 January 2000
1 95 February 2001
2 105 March 2002
3 115 April 2003
4 125 May 2004
5 135 June 2005
With this, depending on one's goals, there are multiple approaches:
Store everything in same dataframe. One approach would be to concat the sheets as follows
sheets = ['Sheet1', 'Sheet2', 'Sheet3']
df = pd.concat([pd.read_excel('FILENAME.xlsx', sheet_name = sheet) for sheet in sheets], ignore_index = True)
[Out]:
0 1 2
0 85 January 2000
1 95 February 2001
2 105 March 2002
3 115 April 2003
4 125 May 2004
5 135 June 2005
6 85 January 2000
7 95 February 2001
8 105 March 2002
9 115 April 2003
10 125 May 2004
11 135 June 2005
12 85 January 2000
13 95 February 2001
14 105 March 2002
15 115 April 2003
16 125 May 2004
17 135 June 2005
Basically, this how pandas.concat
works (Source):

Store each sheet in a different dataframe (let's say, df1
, df2
, ...)
sheets = ['Sheet1', 'Sheet2', 'Sheet3']
for i, sheet in enumerate(sheets):
globals()['df' + str(i + 1)] = pd.read_excel('FILENAME.xlsx', sheet_name = sheet)
[Out]:
# df1
0 1 2
0 85 January 2000
1 95 February 2001
2 105 March 2002
3 115 April 2003
4 125 May 2004
5 135 June 2005
# df2
0 1 2
0 85 January 2000
1 95 February 2001
2 105 March 2002
3 115 April 2003
4 125 May 2004
5 135 June 2005
# df3
0 1 2
0 85 January 2000
1 95 February 2001
2 105 March 2002
3 115 April 2003
4 125 May 2004
5 135 June 2005
Notes:
If one wants to know the sheets names, one can use the ExcelFile
class as follows
sheets = pd.ExcelFile('FILENAME.xlsx').sheet_names
[Out]: ['Sheet1', 'Sheet2', 'Sheet3']
In this case one is assuming that the file FILENAME.xlsx
is on the same directory as the script one is running.
If the file is in a folder of the current directory called Data, one way would be to use r'./Data/FILENAME.xlsx'
create a variable, such as path
as follows
path = r'./Data/Test.xlsx'
df = pd.read_excel(r'./Data/FILENAME.xlsx', sheet_name=None)
This might be a relevant read.