Can anyone please help me to write code if sheet names are matching in several files then data will merge and create one data frame. I want to merge multiple file in one dictionary.
I am getting this error:
> AttributeError
Traceback (most recent call last)
Cell In[78], line 8
6 path = os.path.join(root, fname)
7 print(path)
----> 8 for sheet_name in path.sheet_names():
9 print(sheet_name)
AttributeError: 'str' object has no attribute 'sheet_names'
Code
import os
from pathlib import Path
# Load the Excel file
#xls_file = pd.ExcelFile(excel_filepath)
# Use additional arguments to read the sheets
df_dict_flex = {}
for root, dirs,files in os.walk('path'):
for fname in files:
xls_file = pd.ExcelFile(os.path.join(root, fname))
print(xls_file)
# Checking sheet names in every excel file
for sheet_name in xls_file.sheet_names:
if sheet_name != 'Portfolios' and sheet_name != 'SP Search Term Report':
df_dict_flex[sheet_name] = file.parse(sheet_name,)
df_dict_flex