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?
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.
read_excel has a parameter sheet_name that allows specifying which sheet is read.
data = pd. read_excel(target_file, sheet_name = None) returns a Dict . When you loop over data you get the keys of the Dict .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With