1

I'm using this line code to get all sheets from an Excel file:

excel_file = pd.read_excel('path_file',skiprows=35,sheet_name=None)

  • sheet_name=None option gets all the sheets.

How do I get all sheets except one of them?

cokeman19
  • 2,405
  • 1
  • 25
  • 40
Pablo
  • 21
  • 3
  • I think you can pass sheet names as a list of strings to `sheet_name`. Please see [pandas.read_excel](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html). You can also mix and match sheet number and names/ – medium-dimensional Nov 15 '22 at 21:00
  • Does this answer your question? [Using Pandas to pd.read\_excel() for multiple worksheets of the same workbook](https://stackoverflow.com/questions/26521266/using-pandas-to-pd-read-excel-for-multiple-worksheets-of-the-same-workbook) – medium-dimensional Nov 15 '22 at 21:04

1 Answers1

1

If all you want to do is exclude one of the sheets, there is not much to change from your base code.

Assume file.xlsx is an excel file with multiple sheets, and you want to skip 'Sheet1'.

One possible solution is as follows:

import pandas as pd

# Returns a dictionary with key:value := sheet_name:df
xlwb = pd.read_excel('file.xlsx', sheet_name=None)
unwanted_sheet = 'Sheet1'

# list comprehension that filters out unwanted sheet
# all other sheets are kept in df_generator
df_generator = (items for keys, items in xlwb.items() 
                if keys != unwanted_sheet)

# get to the actual dataframes
for df in df_generator:
    print(df.head())
ferreiradev
  • 327
  • 5
  • 16