I had a csv file looking like this:

```
index label observation groundTruth
0     1     10.00       0
1     3      5.50       0
2     1     18.90       1
---------------------------
3     1     12.00       1
4     3     23.68       0
5     1     21.45       0
6     3      6.57       1
7     1     10.00       1

```

These data represents time series observations where each chain has a set lenght of 5. Since not all observation chains are 5 long by default, some padding was added to artifically increase length using this code to get this file:

```
index label observation groundTruth
0     1     10.00       0
1     3      5.50       0
2     1     18.90       1
3     0        0        0
4     0        0        0
--------------------------
5     1     12.00       1
6     3     23.68       0
7     1     21.45       0
8     3      6.57       1
9     1     10.00       1

```

This is the code:

```
line = [0,0,0]

with open(input_file, 'r') as inp, open(output_file, 'a') as out:
    writer = csv.writer(out)
    reader = csv.reader(inp)
    counter = 0

    for row in reader:
        counter += 1
        if(row[0]=='s' and counter<6):
            while(counter<6):
                writer.writerow(line)
                counter+=1
            counter=0
        else:
            writer.writerow(row)

```

My problem is, this padding needs to be at the beginning of each sequence, not the end.

What I need is the file to look like this:

```
index label observation groundTruth
0     0        0        0
1     0        0        0
2     1     10.00       0
3     3      5.50       0
4     1     18.90       1
--------------------------
5     1     12.00       1
6     3     23.68       0
7     1     21.45       0
8     3      6.57       1
9     1     10.00       1

```

I tried simply reversing the output csv file like this:

```
with open('data/test.csv', 'r') as inp, open('data/test_reverse.csv', 'a') as out:
    writer = csv.writer(out)
    reader = csv.reader(inp)

    for row in reversed(list(reader)):
        writer.writerow(row)

```

but this reverses the full time series which again produces non-sensible data that I do not want:

```
index label observation groundTruth
0     0        0        0
1     0        0        0
2     1     18.90       1
3     3      5.50       0
4     1     10.00       0
--------------------------
5     1     10.00       1
6     3      6.57       1
7     1     21.45       0
8     3     23.68       0
9     1     12.00       1

```

Any idea how to achive this?

Note: The `---` is not part of my .csv, it is just there as help to make the problem clearer.

Note 2: Padding lines can be reliably detected, as `label 0` is not a natural occurence within the data. (In case that helps solve the problem).