title: Is there a way to compare and replace data between 2 dataframe in pandas?
body: <p>I would like to clean data based on the range from different data frame.</p>
  <p>Range data looks like</p>
  <pre><code>labs_range= pd.DataFrame({&quot;Lab&quot;:['Albumin','Sodium','Potassium'],'low': [2,2,3],
                           'high':[4,5,4]})
  
      Lab low high
  0   Albumin 2   4
  1   Sodium  2   5
  2   Potassium   3   4
  </code></pre>
  <p>and data I would like to clean looks like :</p>
  <pre><code>labs = pd.DataFrame({&quot;Albumin&quot;:[1,1,2,1,2,3,4,5],'Calcium':[1,1,2,1,2,3,4,5],'Sodium':[1,1,2,1,2,3,4,5]})
  
  
  
  Albumin Calcium Sodium
  0   1   1   1
  1   1   1   1
  2   2   2   2
  3   1   1   1
  4   2   2   2
  5   3   3   3
  6   4   4   4
  7   5   5   5
  </code></pre>
  <p>I can do it by using a loop but it would take too long if we have data that is big.</p>
  <pre><code>for i in labs_range['Lab']:
      try:
          labs[i] = np.where((labs[i]&lt;labs_range.loc[labs_range['Lab']==str(i),'low'].values[0]) | (labs[i]&gt;labs_range.loc[labs_range['Lab']==str(i),'high'].values[0]),np.nan,labs[i])
      except:
          print(i)
  </code></pre>
  <p>The result that we get from this loops is correct but would like it to be more efficient.</p>
  <pre><code>    Albumin Calcium Sodium
  0   nan 1   nan
  1   nan 1   nan
  2   2.00000 2   2.00000
  3   nan 1   nan
  4   2.00000 2   2.00000
  5   3.00000 3   3.00000
  6   4.00000 4   4.00000
  7   nan 5   5.00000
  </code></pre>