title: Merging Two Data Frames With Matching
body: <p>I have two data frames df1:
  <a href="https://i.stack.imgur.com/2gYIN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2gYIN.jpg" alt="enter image description here"></a></p>
  
  <p>and df2:<a href="https://i.stack.imgur.com/g2A1D.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g2A1D.jpg" alt="enter image description here"></a></p>
  
  <p>I want to join these two data frames to get df3:<a href="https://i.stack.imgur.com/Rapnn.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Rapnn.jpg" alt="enter image description here"></a></p>
  
  <p>Here is the logic that I am trying to build:</p>
  
  <ol>
  <li>df1 is the primary table. The first row of DF3 is populated by searching DF2 for the same ID. The logic finds ID 1 at location A with a value of 50.</li>
  <li>The second row of DF3 is populated by searching for ID 1 in DF2. 50 is already found , so the remaining 50 is allocated to location D.
  3.The third row of DF3 is populated because there is an exact match with location C of 200</li>
  <li>THe fourth row of DF3 is populated with an amount of 250 in location A.</li>
  <li>The fifth row of DF3 is populated with the remaining 50 in DF1 ( not 100)</li>
  <li>IF there is no location match, DF3 location should be null / unknown.</li>
  </ol>
  
  <p>Is there a join that i can perform to do this ?  </p>