How can I loop over 2 folders? In Apple and all its subfolders, I want to look for Excel files that contain "green". In Banana, I want to look for files that contain "yellow". I explicitly need to specify the folder paths and can't just loop over the whole C drive.
import os
folders = ['C:/Desktop/apple', 'C:/Downloads/banana']
for x in in range(len(folders)):
for root, dirs, files in os.walk(folders[i]):
for file in files:
if file.endswith(".xlsx") and "banana" in folders[i] and "yellow" in file:
df = pd.read_excel(os.path.join(root, file))
df['date'] = pd.to_datetime(df.date)
...
if file.endswith(".xlsx") and "apple" in folders[i] and "green" in file:
df = pd.read_excel(os.path.join(root, file))
df['date'] = pd.to_datetime(df.date)
...
Since all the excel files look the same, my code above is cumbersome since I'm duplicating the code to read the dataframe and clean the df.