'Read multiple Excel files with slight differences in sheet names

I am trying to import multiple excel files with multiple sheets. The sheets reference the quarter and have Q1, Q2 , Q3 and Q4 in their names, which I want to be on separate data frames. However, some excel files have sheet names like QTR1 or Qtr1 instead. I want to know if there's a way I can read in sheets with the name Q1, QTR1 and Qtr1? The following is the code I already have but it doesn't produce a dataframe:


import pandas as pd 
import re 

file_path = 'W/Energy-data/Prices/Company_Q1.xlsx'
file=pd.ExcelFile(file_path)

file.sheetnames

dataframes =[]
for sheet in file.sheet_names:
if re.match('Q1*', sheet) or re.match('Qtr 1*', sheet) or re.match('QTR 1*', sheet):
dataframes.append(pd.read_excel(file_path, sheet_name=sheet))






Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source