This is a follow up question to get first and last values in a groupby
How do I drop first and last rows within each group?
I have this df
I'd apply a similar technique to what I did for the other question:
def first_last(df):
return df.ix[1:-1]
df.groupby(level=0, group_keys=False).apply(first_last)
Note: in pandas version 0.20.0 and above, ix is deprecated and the use of iloc is encouraged instead.
So the df.ix[1:-1]
should be replaced by df.iloc[1:-1]
.