in this case I want to bring the highest values of each id but in different quantities. That is, I'm looking for the 5 highest values for the 'id'=1, the 3 highest values for the 'id'=2, etc. I have this code that only brings me a fixed amount of values per group.
import random
df = pd.DataFrame({'id':[1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4]})
df['value'] = np.random.randint(0, 99, df.shape[0])
df.groupby(['id']).apply(lambda x: x.nlargest(2,['value'])).reset_index(drop=True)
id = 1 --> 5
id = 2 --> 3
id = 3 --> 2
id = 4 --> 2