I'm trying to write a script in Python to read the last element (bottom right) of .csv files (File001-..-File010) inside N folders (Folder001-..-Folder006) and make some operations (total 10*6 = 60 .csv files). The .csv files have number of rows variable.
My idea for the script:
- N is the number of folders and P is the number of .csv files inside each folders;
- Enter the folder 1, enter the P .csv files only to read their last element (bottom right) and write it down in a list (of P elements);
- Sum all the elements in this list and write the result in the list output (of N elements)
- Do the same for folder 2 etc..
I would need some help to read the .csv file and its last element within the loop. I read many posts but I am not able to apply them unfortunately.
N = 6
P = 10
def calculate_output(N, P):
output = []
for i in range(N):
for j in range(P):
prob = []
if FILE NAMES ENDS WITH (".csv") in "./Folder00"+str(i+1):
prob.append(BOTTOM RIGHT ELEMENT OF THE FILE)
output.append(sum(prob[p] for p in range(P)))
return output