Follow up question from here: drop first and last row from within each group
In pandas, how do you drop the last row in the first groupby then the first row for all subsequent entries in the group?
e.g
X Y
a a 0 1
a 2 3
c 4 5
d 6 7
b e 8 9
f 10 11
g 12 13
c h 14 15
i 16 17
d j 18 19
I want this
X Y
a d 6 7
b e 8 9
c h 14 15
d j 18 19