title: Pandas efficient way of changing column value based on condition
body: <p>I have a large dataframe where I would like to change values of certain rows based on values of other columns. The problem with my for loop is that it takes very long for large datasets.</p>
  <p>The dataframe has colums similar to</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>label</th>
  <th>prediction</th>
  <th>proba_label1</th>
  <th>proba_label2</th>
  <th>proba_label3</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>label1</td>
  <td>label2</td>
  <td>0.3</td>
  <td>0.6</td>
  <td>0.1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>In this case since pred_label2 is &lt; 0.9, the value of colum &quot;prediction&quot; should change to &quot;label1&quot;</p>
  <pre><code>for i, row in df.iterrows():
      pred_label = row['prediction']
      proba_label = 'proba_' + pred_label
      probability = row[proba_label]
      if probability &lt;= 0.9:
          df.at[i, 'prediction'] = row['label']
  </code></pre>
  <p>Example DF</p>
  <pre><code>data = {'host': ['A','B','A'],
         'label': ['label1', 'label2', 'label1'],
         'prediction': ['label1', 'label3', 'label3'],
         'proba_label1': [0.9, 0.03, 0.2],
         'proba_label3': [0.1, 0.95, 0.75],
         'proba_label2': [0, 0.02, 0.05]
         }
  
  df = pd.DataFrame(data)
  </code></pre>