How to change specific cell values in a pandas dataframe column series based on multiple conditions?
<p>I am trying to <strong>replace all values</strong> in a pandas dataframe column <code>df.column_A</code> <strong>if they fall within the range</strong> of 1 to 10.</p>
<p>However, when I do:</p>
<pre><code>df.loc[(1 &lt; df.column_A &lt; 10), &quot;Column_A&quot;] = 1
</code></pre>
<p>Produces:</p>
<pre><code>ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
</code></pre>
<p>Alternatively, when I do:</p>
<pre><code>df.loc[(df.column_A &lt; 10) &amp; (df.column_A &gt; 1), &quot;df.column_A&quot;] = 1
</code></pre>
<p>I am not getting an error at all, but the values don't get replaced.</p>
<p>What is strange is that when I do:</p>
<pre><code>df.loc[(df.column_A &lt; 10) | (df.column_A &gt; 1), &quot;df.column_A&quot;] = 1
</code></pre>
<p>all values in <code>df.column_A</code> get replaced with <code>1</code>, as I would expect.</p>
<p>This means that the syntax of the line is correct, so the mistake must be due to some factors I don't understand.</p>
<p>What am I doing wrong?</p>