I am trying to group a DataFrame by 2 columns (see example below). For the first column, I want each value to belong to a group. For the second column, I want to group by overlapping intervals of unequal size.
My understanding is that pd.cut() only allows me to group by non-overlapping intervals.
Here is an example:
0 1 2
0 0 4 1721
1 0 5 2353
2 0 6 58
3 0 7 524
4 1 1 1934
5 1 2 1318
6 1 2 1307
7 1 2 301
8 1 2 502
9 1 3 996
10 1 3 32
By grouping by column 0 and 1 I want:
0 1 2
0 [4,5] [1721,2353]
[5,6] [2353,58]
[6,7] [58,524]
1 [1,2] [1934,1318,1307,301,502]
[2,3] [1318,1307,301,502,996,32]
I would then take mean or std of column 2. Any suggestion? Thanks !