how to select top 5 in every group pandas
df.groupby('id').apply(lambda x : x.sort_values(by = 'value', ascending = False).head(2).reset_index(drop = True))
#Alter native
df.groupby(['id']).apply(lambda x: x.nlargest(topk,['value'])).reset_index(drop=True)