title: Faster Alternative to Iterrows() while looping through dataframe
body: <p>I'm trying to find an alternative to looping through a dataframe from a list of given column and replacing all the 'nan' which specific values that i want. Right now I'm using iterrows which is super slow, is there an alternative to this?</p>
  <p>Basically what I have is some columns with NAN values, these columns should only contain 1s or 0s. So what I to do is replace the NAN in each row by the percentage of 1s and 0s that already existed in each column. Lets say column_T has 30% 1s and 70% 0s, so for every iteration i want to pass it through a randint() condition, and if it less than the 30% threshold it would input in 1 for that particular row and vice versa for 0 this would continue for every existing row of NAN.</p>
  <p>Example Df.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">Column_T</th>
  <th style="text-align: right;">Column_I</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: right;">1</td>
  </tr>
  <tr>
  <td style="text-align: left;">0</td>
  <td style="text-align: right;">1</td>
  </tr>
  <tr>
  <td style="text-align: left;">nan</td>
  <td style="text-align: right;">nan</td>
  </tr>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: right;">0</td>
  </tr>
  <tr>
  <td style="text-align: left;">nan</td>
  <td style="text-align: right;">0</td>
  </tr>
  <tr>
  <td style="text-align: left;">0</td>
  <td style="text-align: right;">nan</td>
  </tr>
  <tr>
  <td style="text-align: left;">1</td>
  <td style="text-align: right;">1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <pre><code>for i, row in target_df.iterrows():
                  for j in missing_col_list:
                      num_missing_obs = target_df[j].value_counts().sort_index()
                      chance_for_0s = (num_missing_obs[0]/(num_missing_obs[1]+num_missing_obs[0]))*100
                  
                      #random assign 1s and 0s for missing data by calculated chance
                      if(str(row[j]) == 'nan'):
                          if (random.randint(0,100) &lt; chance_for_0s): 
                              target_df.at[i,j] = 0.0
                          else:
                              target_df.at[i,j] = 1.0
  </code></pre>