title: How to change values in a pandas DataFrame column based on a condition in Python
body: <p>I wanted to change the value of my row where if the column &quot;state&quot; had the value of &quot;CANCELLED&quot; then it would change the row value from column &quot;Activity&quot; into &quot;Cancelled&quot;</p>
  <p>It should be like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>ID</th>
  <th>Activity</th>
  <th>state</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>created</td>
  <td>CANCELLED</td>
  </tr>
  <tr>
  <td>1</td>
  <td>completed</td>
  <td>CANCELLED</td>
  </tr>
  <tr>
  <td>2</td>
  <td>created</td>
  <td>FINNISHED</td>
  </tr>
  <tr>
  <td>2</td>
  <td>completed</td>
  <td>FINISHED</td>
  </tr>
  <tr>
  <td>3</td>
  <td>created</td>
  <td>REJECTED</td>
  </tr>
  <tr>
  <td>3</td>
  <td>rejected</td>
  <td>REJECTED</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>what i tired using <code>df.loc[df.state == &quot;CANCELLED&quot;, &quot;Activity&quot;] = &quot;cancelled&quot;</code></p>
  <p>It did changed the Activity but i still wanted the created activity to be the same.</p>
  <p>There's also an error</p>
  <pre><code>C:\Users\aldev\miniconda3\lib\site-packages\pandas\core\indexing.py:1720: SettingWithCopyWarning: 
  A value is trying to be set on a copy of a slice from a DataFrame.
  Try using .loc[row_indexer,col_indexer] = value instead
  
  See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
    self._setitem_single_column(loc, value, pi)
  </code></pre>
  <p>If anyone has an answer thank you in advance</p>