I have a dataframe
value id
100 1
200 1
300 1
500 2
600 2
700 3
I want to group by id and add lines to the 1st line and after the last line of each group, so my framework looks like this: I add a line with a value 0
value id
0 1
100 1
200 1
300 1
0 1
0 2
500 2
600 2
0 2
0 3
700 3
0 3
Now for each id group, I want to add a sequence column to:
value id sequence
0 1 1
100 1 2
200 1 3
300 1 4
0 1 5
0 2 1
500 2 2
600 2 3
0 2 4
0 3 1
700 3 2
0 3 3
The last part is simple, but I'm looking for how to add lines before and after each group?
source
share