title: Pandas per group imputation of missing values
body: <h2>How can I achieve such a per-country imputation for each indicator in pandas?</h2>
  
  <p>I want to impute the missing values per group</p>
  
  <ul>
  <li><em>no-A-state</em> should get <code>np.min</code> per indicatorKPI </li>
  <li><em>no-ISO-state</em> should get the <code>np.mean</code> per indicatorKPI</li>
  <li><p>for states with missing values, I want to impute with the per <code>indicatorKPI</code> mean. Here, this would mean to impute the missing values for Serbia</p>
  
  <p>mydf = pd.DataFrame({'Country':['no-A-state','no-ISO-state','germany','serbia', 'austria', 'germany','serbia', 'austria',], 'indicatorKPI':[np.nan,np.nan,'SP.DYN.LE00.IN','NY.GDP.MKTP.CD','NY.GDP.MKTP.CD', 'SP.DYN.LE00.IN','NY.GDP.MKTP.CD', 'SP.DYN.LE00.IN'], 'value':[np.nan,np.nan,0.9,np.nan,0.7, 0.2, 0.3, 0.6]})
  <a href="https://i.stack.imgur.com/axpWR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/axpWR.jpg" alt="enter image description here"></a></p></li>
  </ul>
  
  <h1>edit</h1>
  
  <p>The desired output should be similar to</p>
  
  <pre><code>mydf = pd.DataFrame({'Country':['no-A-state','no-ISO-state', 'no-A-state','no-ISO-state',
                                  'germany','serbia','serbia', 'austria', 
                                  'germany','serbia', 'austria',],
                     'indicatorKPI':['SP.DYN.LE00.IN','NY.GDP.MKTP.CD', 'SP.DYN.LE00.IN',
                                     'SP.DYN.LE00.IN','NY.GDP.MKTP.CD','SP.DYN.LE00.IN','NY.GDP.MKTP.CD','NY.GDP.MKTP.CD', 'SP.DYN.LE00.IN','NY.GDP.MKTP.CD', 'SP.DYN.LE00.IN'],
                       'value':['MIN of all for this indicator', 'MEAN of all for this indicator','MIN of all for this indicator','MEAN of all for this indicator', 0.9,'MEAN of all for SP.DYN.LE00.IN indicator',0.7, 'MEAN of all for NY.GDP.MKTP.CD indicator',0.2, 0.3, 0.6]
                     })
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/pvHoo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pvHoo.jpg" alt="enter image description here"></a></p>