I need to import all excel files in my directory, including sub directories, but I keep getting into an error message because there are other types of files in the same directory such as pdf and word. How do I my current code below to ignore all other types of files and only import excel files wit the xlsx extension.
for subdir, dirs, files in os.walk(data_path):
for file in files:
df_file = pd.read_excel(subdir + '/' +file)
df_file.set_index(df_file.columns[0], inplace=True)
df_total = pd.concat([df_file, df_total], ignore_index=True)
I tried something like if file.endswith("xlsx"): but it didn't work.
Thank you in advance.