title: filtering pandas dataframe with and without using .loc
body: <p>I have a simple question regarding the concept of filtering a dataframe. suppose I have the below dataframe:</p>
  
  <pre><code>df = pd.DataFrame({'AAA': [4, 5, 6, 7],'BBB': [10, 20, 30, 40],'CCC': [100, 50, -30, -50]})
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dVzJ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dVzJ2.png" alt="df"></a></p>
  
  <p>I would like to perform some modifications on it base on some conditions.
  If I run the below code I get my desired row:</p>
  
  <blockquote>
    <p>Method a</p>
  </blockquote>
  
  <pre><code>df[(df.AAA &lt;= 5) &amp; (df.BBB &lt;= 10)]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Dyj3o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dyj3o.png" alt="a"></a></p>
  
  <p>I can also get that row with the below code:</p>
  
  <blockquote>
    <p>Method b</p>
  </blockquote>
  
  <pre><code>df.loc[(df.AAA &lt;= 5) &amp; (df.BBB &lt;= 10)]
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/eSw3B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eSw3B.png" alt="b"></a></p>
  
  <p>Both of Method a and Method b, resulted in pandas dataframe.
  However when I want to modify column "CCC" based on those conditions, I get error with the "Method a":</p>
  
  <blockquote>
    <p>Method a</p>
  </blockquote>
  
  <pre><code>df[(df.AAA &lt;= 5) &amp; (df.BBB &lt;= 10), 'CCC'] = -1
  </code></pre>
  
  <blockquote>
    <p>'Series' objects are mutable, thus they cannot be hashed</p>
    
    <p>Method b</p>
  </blockquote>
  
  <pre><code>df.loc[(df.AAA &lt;= 5) &amp; (df.BBB &lt;= 10), 'CCC'] = -1
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/NesmX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NesmX.png" alt="b-1"></a></p>