Premium problem62. Named Aggregations per Group

Medium Locked

Group df by animal and return one row per animal with two plain (non-MultiIndex) columns: total_visits, the sum of that animal's visits, and avg_age, the mean of that animal's age.

Input

  animal  age  visits priority
a    cat  2.5       1      yes
b    cat  3.0       3      yes
c  snake  0.5       2       no
d    dog  NaN       3      yes
e    dog  5.0       2       no
f    cat  2.0       3       no
g  snake  4.5       1       no
h    cat  NaN       1      yes
i    dog  7.0       2       no
j    dog  3.0       1       no

Output

        total_visits  avg_age
animal                       
cat                8      2.5
dog                8      5.0
snake              3      2.5

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)