Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Concat multiple Excel sheets with exclusion
#1
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. Shifty

Is that possible?

Thanks!
Quote
#2
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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Comparing data from two Excel sheets Stuart_Houghton 0 157 Jan-19-2020, 02:49 PM
Last Post: Stuart_Houghton
  Getting Cells from the Sheets "automate the boring stuff" Shafla 8 356 Sep-24-2019, 04:53 AM
Last Post: snippsat
  Linking python to Google Sheets Charliefish1311 1 422 Jul-09-2019, 12:31 AM
Last Post: micseydel
  Automating Excel sheets with Python wendysling 1 498 Mar-15-2019, 01:39 PM
Last Post: Larz60+
  Iterate over excel-sheets using xlrd tobbs 6 4,280 Feb-28-2019, 08:33 PM
Last Post: tobbs

Forum Jump:


Users browsing this thread: 1 Guest(s)