There is a nice technique I learned from @bkamins here: Creating User-Defined Grouped DataFrames That might work well for your particular use case. In my linked post, basically, you group by creating a “dummy” column that groups based on how you want the grouping logic defined. This might be a more concise approach to your solution. Hope it helps!