title: How to compare cell values of two different DataFrames in Python?
body: <p>I have two DataFrames:</p>
  
  <p><strong>Person_df</strong></p>
  
  <p>       </p>
  
  <pre><code>Name  Emplid  Country
  
      0  DK     123    India
  
      1  JS     456    India
  
      2  RM     789    China
  
      3  MS     111    China
  
      4  SR     222    China
  </code></pre>
  
  <p> <strong>Target_df</strong></p>
  
  <p>        </p>
  
  <pre><code>Country Category    Target
  
      0   India   Marketing   Reduce spend by $xy.
  
      1   India   R&amp;D         Increase spend by $dd.
  
      2   India   Infra       Reduce spend by $kn.
  
      3   China   Marketing   Increase spend by $eg.
  
      4   China   R&amp;D         Increase spend by $cb.
  
      5   China   Infra       Reduce spend by $mn.
  </code></pre>
  
  <p>My aim is to create a third DataFrame based on the country of each person, which would look like this:</p>
  
  <p><strong>Individual_df</strong></p>
  
  <p>    </p>
  
  <pre><code>TargetID    Category    Target
  
      DK12301     Marketing   Reduce spend by $xy.
  
      DK12302     R&amp;D         Increase spend by $dd.
  
      DK12303     Infra       Reduce spend by $kn.
  
      JS45601     Marketing   Reduce spend by $xy.
  
      JS45602     R&amp;D         Increase spend by $dd.
  
      JS45603     Infra       Reduce spend by $kn.
  
      RM78901     Marketing   Increase spend by $eg.
  
      RM78902     R&amp;D         Increase spend by $cb.
  
      RM78903     Infra       Reduce spend by $mn.
  
      MS11101     Marketing   Increase spend by $eg.
  
      MS11102     R&amp;D         Increase spend by $cb.
  
      MS11103     Infra       Reduce spend by $mn.
  
      SR22201     Marketing   Increase spend by $eg.
  
      SR22202     R&amp;D         Increase spend by $cb.
  
      SR22203     Infra       Reduce spend by $mn.
  </code></pre>
  
  <p>Basically I have to take a person from Person_df, match his/her country with country mentioned in Target_df and then assign each of this target to this person(and store in Individual_df). </p>
  
  <p>Problem is, I am new to python and can't really figure out how to carry out this comparison of country.</p>
  
  <p>I wrote the code below:</p>
  
  <p>    </p>
  
  <pre><code>for index, row in Person_df.iterrows():
  
       
  
          for index1, row1 in Goals_df.iterrows():
  
              If Person_df['country'] == Person_df['country'] : #I know this is incorrect
  
                  data = [] 
  
                  #populate data[] with selected values for one person.
  
                  #append data[] to Individual_df
  </code></pre>
  
  <p>I need help on couple of points here:</p>
  
  <p>1) How really I can perform the comparison here for country of each person.</p>
  
  <p>2) Even if I know how to compare, the code I wrote is not at efficient as I am doing loads of unnecessary iterations here. Any pointers how can I improve this?</p>
  
  <p>Thanks!</p>