Concat multiple Excel sheets with exclusion - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Concat multiple Excel sheets with exclusion (/thread-23636.html) |
Concat multiple Excel sheets with exclusion - alessandrotk - Jan-09-2020 import pandas as pd workbook_url = 'C:/file.xlsx' df = pd.concat(pd.read_excel(workbook_url, sheet_name=None), ignore_index=True, sort=False)Can someone help me concat all sheets from my Excel file, but excluding two Sheets called 'Main' and 'Info'? In this case I don't want to manually specify all sheet names that I want to load, but in instead I want to specify the ones that I don't want to load. Is that possible? Thanks! RE: Concat multiple Excel sheets with exclusion - sandeep_ganga - Jan-10-2020 May be try this to see if that helps, import pandas as pd xl = pd.ExcelFile('test123.xlsx') a=xl.sheet_names print(a)# original sheet names list exclusionlist=["Sheet1","Sheet4"]# exclusion list for item in exclusionlist: a.remove(item) print(a)#now "a" have remaining sheetnames workbook_url = 'test123.xlsx' #df = pd.read_excel(workbook_url, sheet_name=a, ignore_index=True) df = pd.concat(pd.read_excel(workbook_url, sheet_name=a), ignore_index=True, sort=False) print(df) #print(df.keys()Best Regards, Sandeep GANGA SANDEEP KUMAR |