I have a dataframe like this one. I need to replace NaN with median value, based on animal type. For example I need to calculate a median for cats and then replace only cats with NaN with this value. Is there a way to do this in one command or I need to do it manually for each type?
animal age weight priority
a cat 2.5 1 yes
b cat 1.0 3 yes
c dog 0.5 6 no
d dog NaN 8 yes
e cat 5.0 4 no
f cat 2.0 3 no
g dog 3.5 10 no
h cat NaN 2 yes
i dog 7.0 7 no
j dog 3.0 3 no