Having the following DF:
A B
0 1 11
1 2 22
2 2 22
3 3 33
4 3 33
I would like to groupby 'A' then take first n groups and create a new data frame from it. I've looked around and found this answer:
result = [g[1] for g in list(grouped)[:3]]
But the solution returns a list and not a DF, furthermore it seems redundant to create a list from the grouped result.
Update:
Expected output is a new DF comprised from the first n groups, for example if n=2
output would be:
A B
0 1 11 <-- first group
1 2 22 <-- second group
2 2 22 <-- second group
Any help would be appreciated