I've got a pandas DataFrame filled with real numbers and categories, but there is a few nan values in it.
How can I replace the nans with mean or median of grouped categories?
      A         B      
0  model 2    0.979728 
1  model 1    0.912674 
2  model 2    0.540679 
3  model 1    2.027325 
4  model 2        NaN  
5  model 1        NaN  
6  model 3   -0.612343 
7  model 1   1.033826  
8  model 1   1.025011  
9  model 2   -0.795876 
in this case i would like to substitute two nan with their relative mean or median.
Thank you in advance
 
    