I have an excel workbook with 4 worksheets with different names. I want to read them into pandas dataframe only if they are called in the variable sheet_names. For example, the entire workbook's sheet names can be ['banana','orange','apple','grape']. Each sheet has 5 columns that I want to read into Python.
import pandas as pd
sheet_names =['grapes','orange'] #sheet_names is what I control... it can contain any number of sheets between 1 to 4.
xlsx = pd.ExcelFile('C:\\Users\\Ken\\Desktop\\Df.xlsx')
df = []
for x in sheet_names:
df.append(xlsx.parse(sheetname=x,index_col=0,parse_cols='B:F'))
However the code returns a list with len = 2.
The desired output is a dataframe with 10 columns. Any help please?