26. Sum of Three Greatest per Group

Hard

df has a group column 'grps' and integer column 'vals'. For each group, return the sum of its three greatest values (as a Series indexed by group).

Input

   grps  vals
0     a    12
1     a   345
2     a     3
3     b     1
4     b    45
5     c    14
6     a     4
7     a    52
8     b    54
9     c    23
10    c   235
11    c    21
12    b    57
13    b     3
14    c    87

Output

grps
a    409
b    156
c    345
Name: vals, dtype: int64

Sign in to write and run your own code.

Implement solve(...)