title: How to change a value in a dataframe using multiple conditions with loc?
body: <p>I want to change a value from a row/column of a dataframe as follows:</p>
  <p>Within the interval, when it found a value which is different equal to 1, then it should put 2.</p>
  <p>The example:</p>
  <p><strong>initial df</strong>:</p>
  <pre><code>index                      event
  2019-12-07 18:30:16         0
  2019-12-07 19:30:16         0           
  2019-12-07 20:30:16         0           
  2019-12-07 21:30:16         0           
  2019-12-07 22:30:16         1
  </code></pre>
  <p><strong>wanted df</strong>:</p>
  <pre><code>index                      event
  2019-12-07 18:30:16         0
  2019-12-07 19:30:16         0           
  2019-12-07 20:30:16         0           
  2019-12-07 21:30:16         0           
  2019-12-07 22:30:16         2
  </code></pre>
  <p>The following code works but I cannot change the value:</p>
  <pre><code>mask = (df.index &gt; start_dates) &amp; (df.index &lt;= end_dates)
  
  for k in range (0, len(df.loc[mask])):
      if df.loc[mask].event[k] == 1:
          df.loc[mask].loc[df.loc[mask].event == 1, &quot;event&quot;] = 2
  </code></pre>
  <p>I cannot change the value from 1 to 2 in the last line of code.</p>
  <p>I also tried this...:</p>
  <pre><code>df.loc[mask].loc[df.loc[mask].event == 1, &quot;event&quot;] = 2
  df.loc[mask].event[df.loc[mask].event == '1'] = 2
  df.loc[mask].event[k] = 2
  </code></pre>
  <p>But none of the above lines works.</p>
  <p>Please help me. :( Any help is highly appreciated!</p>