Python pandas remove rows where multiple conditions are not met
<p>Lets say I have a dataframe like this:</p>

<pre><code>   id  num
0   1    1
1   2    2
2   3    1
3   4    2
4   1    1
5   2    2
6   3    1
7   4    2
</code></pre>

<p>The above can be generated with this for testing purposes:</p>

<pre><code>test = pd.DataFrame({'id': np.array([1,2,3,4] * 2,dtype='int32'),
                     'num': np.array([1,2] * 4,dtype='int32')
                    })
</code></pre>

<p>Now, I want to keep only the rows where a certain condition is met: <code>id</code> is not 1 AND <code>num</code> is not 1. Essentially I want to remove the rows with index 0 and 4. For my actual dataset its easier to remove the rows I dont want rather than to specify the rows that I do want</p>

<p>I have tried this:</p>

<pre><code>test = test[(test['id'] != 1) &amp; (test['num'] != 1)]
</code></pre>

<p>However, that gives me this:</p>

<pre><code>   id  num
1   2    2
3   4    2
5   2    2
7   4    2
</code></pre>

<p>It seems to have removed all rows where <code>id</code> is 1 OR <code>num</code> is 1</p>

<p>I've seen a number of other questions where the answer is the one I used above but it doesn't seem to be working out in my case</p>