xxxxxxxxxx
df.sort_values('frequency', ascending=False).groupby('short_name').head(2)
Out[28]:
short_name product_id frequency
4 Yoghurt Bebible 21329 68
5 Yoghurt Bebible 21328 67
0 Yoghurt y cereales 975009684 32
1 Yoghurt y cereales 975009685 21
3 Yoghurt y Cereales 21097 16
xxxxxxxxxx
In [5]: df.groupby('short_name', as_index=False).apply(lambda x: x.nlargest(2, 'frequency'))
Out[5]:
short_name product_id frequency
0 4 Yoghurt Bebible 21329 68
5 Yoghurt Bebible 21328 67
1 3 Yoghurt y Cereales 21097 16
2 0 Yoghurt y cereales 975009684 32
1 Yoghurt y cereales 975009685 21