title: Replacing values with groupby means
body: <p>I have a DataFrame with a column that has some bad data with various negative values. I would like to replace values &lt; 0 with the mean of the group that they are in.</p>
  
  <p>For missing values as NAs, I would do:</p>
  
  <pre><code>data = df.groupby(['GroupID']).column
  data.transform(lambda x: x.fillna(x.mean()))
  </code></pre>
  
  <p>But how to do this operation on a condition like <code>x &lt; 0</code>?</p>
  
  <p>Thanks!</p>