Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas.read_excel parameter "sheet_name" not working

According to pandas doc for 0.21+, pandas.read_excel has a parameter sheet_name that allows specifying which sheet is read. But when I am trying to read the second sheet from an excel file, no matter how I set the parameter (sheet_name = 1, sheet_name = 'Sheet2'), the dataframe always shows the first sheet, and passing a list of indices (sheet_name = [0, 1]) does not return a dictionary of dataframes but still the first sheet. What might be the problem here?

like image 659
anonymum Avatar asked Dec 26 '17 08:12

anonymum


People also ask

How do you read a specific Excel sheet in pandas?

To read an excel file as a DataFrame, use the pandas read_excel() method. You can read the first sheet, specific sheets, multiple sheets or all sheets. Pandas converts this to the DataFrame structure, which is a tabular like structure.

What is sheet name in read_excel?

read_excel has a parameter sheet_name that allows specifying which sheet is read.

What does PD read_excel return?

data = pd. read_excel(target_file, sheet_name = None) returns a Dict . When you loop over data you get the keys of the Dict .


1 Answers

It looks like you're using the old version of Python. So try to change your code

df = pd.read_excel(file_with_data, sheetname=sheet_with_data)

It should work properly.

like image 179
Sergey Solod Avatar answered Oct 14 '22 22:10

Sergey Solod