Python : Multiple excel files in folders and sub-folders
I have a folder with the following structure,
Folder |_ File1.xlsx |_ File1.xlsx ... |_ Folder2.xlsx |_File3.xlsx |_File4.xlsx
There are three aims that I want to fulfill,
List out all files in folders and sub-folders.
Open all files one-by-one.
- Copy the columns 1, 3 and 8 and store it in another excel file.
As of now, I have successfully done (1) and the code is as follows, import os
rootdir = os.getcwd()
for subdir, dirs, files in os.walk(rootdir): for file in files: filepath = subdir + os.sep + file if filepath.endswith(".xlsx"): print (filepath)
However, I am stuck at (2), I have tried to think of ways (and google) to get around it and have failed.
Any kind of help will be appreciated.
Thanks in advance.