I am running a loop where I am reading all the docx files in a folder in multiple dataframes. I need to save each document into different dataframes and name each dataframes as same as the name of the files. Note: I am refraining to store the dataframes in a dictionary with the filenames as keys.
for root, dirs, files in os.walk(directory):
for document in files:
if document.endswith('.docx'):
table_num=4
nheader=2
joined_path = os.path.join(directory,document)
document1 = Document(joined_path)
table =document1.tables[table_num-1]
data=[[cell.text for cell in row.cells] for row in table.rows]
df = pd.DataFrame(data)
outside_col,inside_col =df.iloc[0],df.iloc[1]
hier_index =pd.MultiIndex.from_tuples(list(zip(outside_col,inside_col)))
df=pd.DataFrame(data,columns=hier_index).drop(df.index[[0,1]]).reset_index(drop=True)
df['company'] = os.path.basename(os.path.normpath(document))
df+_+str(os.path.basename(os.path.normpath(document))) = df # tried here and getting error