0

I have an excel file with the name F_Path.xlsx listing the folder paths like below: enter image description here

path = "C:/Users/Axel/Documents/Work/F_Path.xlsx" 
df_input = pd.read_excel(path1, sheet_name=0) #reading the excel file
folder_path = list(df_input['Folder Path']
path_csv = #1st csv file from C:/Users/Axel/Documents/Work/Folder_1, then 2nd read in for loop, but don't know how.. once all the csv are read from Folder_1, it has to read folder_path[1 to n] and read all the csv files and process it separately.

.
.
.
.
.
df = pd.read_csv(path_csv)  # read all the *.csv file one by one and process each df separately.

#process the data

1 Answer 1

1

Try the following:

# you'll need to import os
import os

# loop your folders
for folder in folder_path:
    # get the csvs in that folder
    csv_files = os.listdir(folder)
    # loop the csvs
    for csvfile in csv_files:
        df = pd.read_csv(os.path.join(folder, csvfile))
        # do your processing here
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.