I have a dataframe df that looks like this:
column_a ...
1
1
1
2
3
3
3
3
3
I now want to group the dataframe based on column_a but the resulting groups should be not of greater size than s.
So, for s=2 the groups should be:
(1,1), (1), (2), (3,3), (3,3), (3).
I have this working with a simple loop over the grouped dataframe (df.groupby(['column_a'])) and splitting the groups if they are too big but I have the feeling there is a shorter and more elegant way to do this.
Does anyone know a short and elegant method to group with a limited group size?