Python Forum
Concat multiple Excel sheets with exclusion
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!
Reply
#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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  DataFRame.concat() nafshar 3 770 Jul-14-2023, 04:41 PM
Last Post: nafshar
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 5,576 Feb-17-2023, 06:01 PM
Last Post: Sameer33
Lightbulb Help using Google Sheets matheuspimenta 0 715 Dec-15-2022, 05:36 PM
Last Post: matheuspimenta
  How to loop through all excel files and sheets in folder jadelola 1 4,449 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  Concat Strings paulo79 5 1,439 Apr-15-2022, 09:58 PM
Last Post: snippsat
  [SOLVED] Concat data from dictionary? Winfried 4 1,715 Mar-30-2022, 02:55 PM
Last Post: Winfried
  Compare two Excel sheets with Python and list diffenrences dmkfon 1 14,599 Oct-09-2021, 03:30 PM
Last Post: Larz60+
  Xlsxwriter: Create Multiple Sheets Based on Dataframe's Sorted Values KMV 2 3,481 Mar-09-2021, 12:24 PM
Last Post: KMV
  identical cells in 2 different excel sheets python pandas esso 0 1,628 Jul-19-2020, 07:50 PM
Last Post: esso
  Multiple excel files Kristenl2784 6 5,954 Jun-12-2020, 06:24 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020