aggregate

Multiple indexing with multiple idxmin() and idmax() in one aggregate in pandas

回眸只為那壹抹淺笑 提交于 2020-08-27 21:57:25
问题 In R data.table it is possible and easy to aggregate on multiple columns using argmin or argmax functions in one aggregate. For example for DT: > DT = data.table(id=c(1,1,1,2,2,2,2,3,3,3), col1=c(1,3,5,2,5,3,6,3,67,7), col2=c(4,6,8,3,65,3,5,4,4,7), col3=c(34,64,53,5,6,2,4,6,4,67)) > DT id col1 col2 col3 1: 1 1 4 34 2: 1 3 6 64 3: 1 5 8 53 4: 2 2 3 5 5: 2 5 65 6 6: 2 3 3 2 7: 2 6 5 4 8: 3 3 4 6 9: 3 67 4 4 10: 3 7 7 67 > DT_agg = DT[, .(agg1 = col1[which.max(col2)] , agg2 = col2[which.min(col3

Combination of columns for aggregation after groupby

守給你的承諾、 提交于 2020-08-09 19:06:12
问题 Question Looking for something like df.groubpy('key').aggregate(combination(columnA, columnB)) instead of df['combination'] = combination(columnA, columnB) df.groupby('key')['combination'].aggregate() The only requirement is that the combination of columns is calculated after the groupby. Description I seems natural, logically wise, for some cases to first groupby and then aggregate. One example would be different aggregate functions for different combinations of columns that use the same