Data frame df1 contains key, value pairs:
key val
0 1 7
1 2 5
2 2 5
3 3 4
4 3 4
5 3 4
How to get data frame df2 that for each key has a record with two fields: cnt equal to the number of times given key is found in df1 and sum equal to the sum of this key values ? Like this:
cnt key sum
0 1 1 7
1 2 2 10
2 3 3 12
You can use
aggwith a list of summary functions: