title: Replace missing value in a row if there's a match in two columns from another row using Pandas
body: <p>I'm working on a data analysis project and I have the following dataframe that looks like this.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">id</th>
  <th style="text-align: center;">store</th>
  <th style="text-align: center;">long</th>
  <th style="text-align: center;">lat</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">A</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">-4</td>
  </tr>
  <tr>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;"><strong>NaN</strong></td>
  <td style="text-align: center;"><strong>2</strong></td>
  <td style="text-align: center;"><strong>3</strong></td>
  </tr>
  <tr>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">C</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">5</td>
  </tr>
  <tr>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;"><strong>D</strong></td>
  <td style="text-align: center;"><strong>2</strong></td>
  <td style="text-align: center;"><strong>3</strong></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I want to fill the missing value NaN in the 'store' column with the one in row with id 4, given that row with id 2 and 4 have the same values in the 'long' and 'lat' columns, so the output should look like this</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: center;">id</th>
  <th style="text-align: center;">store</th>
  <th style="text-align: center;">long</th>
  <th style="text-align: center;">lat</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">A</td>
  <td style="text-align: center;">1</td>
  <td style="text-align: center;">-4</td>
  </tr>
  <tr>
  <td style="text-align: center;">2</td>
  <td style="text-align: center;"><strong>D</strong></td>
  <td style="text-align: center;"><strong>2</strong></td>
  <td style="text-align: center;"><strong>3</strong></td>
  </tr>
  <tr>
  <td style="text-align: center;">3</td>
  <td style="text-align: center;">C</td>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;">5</td>
  </tr>
  <tr>
  <td style="text-align: center;">4</td>
  <td style="text-align: center;"><strong>D</strong></td>
  <td style="text-align: center;"><strong>2</strong></td>
  <td style="text-align: center;"><strong>3</strong></td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I want to do this for a long dataframe (almost a million rows), so I don't know the row ids that have the same 'long' and 'lat' values.</p>
  <p>I'm working on Python using Pandas. I've only come up with this solution using <em>for loops</em> and iterrows(), which is super slow</p>
  <pre><code>df_missing_names = df[df['store'].isna()] #rows that have missing names
  df_with_names = df[df['store'].notna()] #rows that don't have missing names
  
  for indx, row in df_missing_names.iterrows(): #run through all the rows that don't have names
  
      for indx_j, row_j in df_with_names.iterrows(): #run through all the rows that have names
  
          if (row.lat == row_j.lat) &amp; (row.long == row_j.long): #if both lat and long values match
              df[indx, 'store'] = row_j.store #then update name of the row in the original dataframe
  </code></pre>
  <p>Is there a faster way to do this using built in functions on Pandas? Thanks for the help</p>