0

I have a loop for importing some data from a large number of excels. However, some of them have hidden first tabs. I would pull a specific tab by name, but there are two different naming conventions used.

This is my code

import pandas as pd
import string
import glob
import os

directory = 'file path'
files = os.listdir(directory)
list_of_dfs = []

os.chdir("C:/Users/nlarmann/Desktop/Q3_JVs")
for file in files:
     df = pd.read_excel (file)
     df = df.T
     df = df.iloc[[1],:24]
     list_of_dfs.append(df)

data_combined = pd.concat(list_of_dfs)
data_combined.to_excel('filepath/output.xlsx', index=False)

I know I could specify a sheet name to target the tab I want, but I am unsure how to make python try two different names, but not require them to be found. I am looking for either a way to make python check two naming conventions, or just ignore all hidden sheets. (The one I want is the first visible sheet).

I realize there is a way to identify if a sheet is hidden or not, but I am uncertain on how to integrate that into my existing code.

I appreciate any assistance.

0 Answers0