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!
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Create a GroupedDataFrame by the relations of rows rather than the values of the rows in a column, e.g `groupby` consecutive dates? | 14 | 815 | March 29, 2023 | |
| Cummulative death by day by country | 29 | 2149 | June 29, 2020 | |
| Splitting time periods in a DataFrame | 10 | 1153 | October 29, 2022 | |
| Transforming a daily DataFrame with missing values into a DataFrame with end-of-month values | 11 | 283 | November 22, 2024 | |
| How to compute a "cumulative" in a dataframe (without a for loop) | 44 | 9882 | September 11, 2021 |