Premium problem64. Within-Group Z-Score

Hard Locked

Return the age column of df, standardized to a z-score within each animal group: for each row, subtract that animal group's mean age and divide by that group's (sample) standard deviation. Return a Series aligned to the original index.

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

a    0.000000
b    1.000000
c   -0.707107
d         NaN
e    0.000000
f   -1.000000
g    0.707107
h         NaN
i    1.000000
j   -1.000000
Name: age, dtype: float64

Premium problem

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

Implement solve(...)