I have a CSV containing the following:
ID Name Series Value
250 A 3 20
250 A 3 40
250 A 3 60
251 B 4 16
251 B 4 18
251 B 4 24
251 B 4 42
The Series column denotes how many elements belong to one another, so taking the first row (not header row), the Series = 3. So I need to gather the number of rows specified by Series, inclusive of the current row. Such that they are grouped like so (by Value):
[(20, 40, 60), (16, 18, 24, 42)]
Essentially, I am moving down through the CSV sequentially, while Series tells me how many of the next rows (including the current one) to gather. If we use the first row again, the value is 3, so my grouping must total 3 rows starting at the current row.
I've read in the CSV and converted it from a Reader to List, but cant quite come up with a solution for actively changing the index of iteration over the rows based upon the value found in series. If I try:
for row in rows...
I end up iterating over every row, I would have to change the value of rows and altering a list while iterating over it is a bad idea. If I try:
for x in range(1, len(rows)...
I cannot devise a method to change where the current x should be.
Seriescolumn already grouped? I.E., it won't go2,2,2, 3,3,3, 2,1,...Seriesdenotes from the current row, how many more rows go together. So if the first row is3, I need a group of that row, plus the next2rows which would give me3total rows. Numbers can repeat again later in the file but are not part of the previous groupings.