I have n excel files and I need to sort them according to a column's value. In fact, I need to organize my excel files placed under a specific folder in creating subfolders and each subfolder contains excel files with the same DEPTNAME, knowing that DEPTNAME is a column name and each excel file has m sheets but all the sheets have the same DEPTNAME.
Example: A folder with 4 excel files:
df1= pd.DataFrame({'Last Name':[‘Stark’, ‘Stark’, ‘ Stark’, ‘Stark’],
'FirstName':['Arya', ,'Arya','Arya','Arya',],
'DEPTNAME':['Sécu','Sécu','Sécu','Sécu']})
df2= pd.DataFrame({'Last Name':[‘Lannister’, ‘Lannister’, ‘ Lannister’, ‘Lannister’],
'FirstName':['Cersei', ,'Cersei','Cersei','Cersei',],
'DEPTNAME':['Auto','Auto','Auto','Auto']})
df3= pd.DataFrame({'Last Name':[‘Snow’, ‘Snow’, ‘ Snow’, ‘Snow’, ‘ Snow’, ‘Snow’],
'FirstName':['Jon', 'Jon','Jon','Jon','Jon','Jon'],
'DEPTNAME':['Aero','Aero','Aero','Aero','Aero','Aero']})
df4= pd.DataFrame({'Last Name':[‘Lannister’, ‘Lannister’, ‘ Lannister’, ‘Lannister’],
'FirstName':['Tyrion', 'Tyrion','Tyrion','Tyrion',],
'DEPTNAME':['Aero','Aero','Aero','Aero']})
Now I need to create automatically 3 folders: Sécu, Aero and Auto.
Sécu will contain one excel file
Aero will contain two excel files
Auto will contain one excel file
is it doable knowing that my initial folder contains n excel files with multiple sheets?



