0

I want to only read the sheet names that start with a number before ". Final Ranked List" for example most sheets are named "4. Final Ranked List" but some are named "3. Final Ranked List". There are some sheets named "Copy of 4. Final Ranked List" for example that I do not want to include.

I've tried adding RegEx in the string, but pandas attempts to read it as the sheet name, not as a modifier.

df = pd.read_excel(file, sheet_name='4. Final Ranked List')

I'm hoping the script will read in all sheets that have a number & '. Final Ranked List' but excluding those that begin with 'Copy of'

BenG
  • 116
  • 1
  • 9

1 Answers1

0

From reading the documentation, it does not seem that this function accepts Regular Expressions as sheet names. You may be able to read in all the sheets at once using sheet_name=None, and then filter out the ones you don't need using a python regex or other string matching.

See here for the function documentation: http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html

See here for another answer to a similar question: https://stackoverflow.com/a/45603247/6705467

alexbclay
  • 1,234
  • 14
  • 17