I am in a directory that holds 36 different folders. Each folder has a single csv in it. I want to append each of these together to make a large data frame in python.
in R, I would do this:
cwd = getwd() #get current directory
fil = list.files() #get list of all files/folders in the directory
Bigdf = NULL #initialize empty df
for(i in fil){ #read through all folders in current directory
setwd(paste0(cwd,'/',i)) #navigate to i'th folder
fil2 = list.files() #get list of files in i'th folder
for(j in fil2){
a = read.csv(paste0(cwd,'/',i,'/',j)) #read in all csv's
Bigdf = rbind(Bigdf,a[,c(2,4:11)]) #append desired columns to data frame
}
setwd(cwd)
}
How would I go about doing something like this in python?
I tried to implement How can I read the contents of all the files in a directory with pandas? and How do I list all files of a directory? and to no avail. I think I am missing something obvious, and hope someone can point me in the right direction.