I have a df as follows-
a b c
x 2 3
y 2 3
z 3 2
w 1 5
(upto thousands of records)
I want to group this dataframe based on b,c such that each group has only n number of rows. If there are any more rows in the same group, I want to create a new group. That is the main problem statement. I also want to delete these groups from the original dataframe if possible.
Sample output (with a little more explanation) -
I basically want to loop on the df and am currently using the following code-
for x,y in df.groupby(['b','c']):
print(y)
With this code Im getting the following groups:
a b c
x 2 3
y 2 3
a b c
z 3 2
a b c
w 1 5
Now lets say I want only 1(n) row in each group, this is the output Im looking for:
a b c
x 2 3
a b c
y 2 3
a b c
z 3 2
a b c
w 1 5
(And maybe delete these groups from the df too if possible)
Thank you!