I have a table like
Fruit Month
----------------
A Jan
A Feb
A Mar
B Sep
I want to filter the table in such a way that I get only top n rows say two for each fruit Example
Fruit Month
----------------
A Jan
A Feb
B Sep
You can just use groupby() and head():
df.groupby('Fruit').head(2)
Outputs:
Fruit Month
0 A Jan
1 A Feb
3 B Sep