I have csv files (present in the same directory) like these:
File1:
Id,Param1,Param2
1,10,12
2,16,18
3,24,28
4,22,26
File2:
Id,Param1,Param2
1,13,19
2,15,23
3,21,25
I want to read the files and create nested lists like this:
Param1 = [[10, 16, 24, 22], [13, 15, 21]]
Param2 = [[12, 18, 28, 26], [19, 23, 25]]
What I tried:
for i in range(1,nof+1,1):
with open("File%i.csv" %i, "rb") as f1:
reader = csv.reader(f1)
for row in reader:
Param1.append(row[1])
Param2.append(row[2])
Finally:
[Param1[i:i + n] for i in range(0, len(Param1), n)]
[Param2[i:i + n] for i in range(0, len(Param2), n)]
Would work fine if I had the same number of rows in all my files, but that isn't the case. My files have unequal number of rows. So, can someone please help me figure out how to go about creating these splits. Many thanks.