Isolating pandas columns using boolean logic in python
<p>I am trying to grab the rows of a data frame that satisfy one or both of the following boolean statements:</p>

<pre><code>1) df['colName'] == 0
2) df['colName'] == 1
</code></pre>

<p>I've tried these, but neither one works (throws errors):</p>

<pre><code>df = df[df['colName']==0 or df['colName']==1]
df = df[df['colName']==0 | df['colName']==1]
</code></pre>

<p>Any other ideas?</p>

<p>you are missing <code>()</code></p>

<pre><code>df = df[(df['colName']==0) | (df['colName']==1)]
</code></pre>

<p>this will probably raise a copy warning but will still works.</p>

<p>if you don't want the copy warning, use an indexer such has:</p>

<pre><code>indexer = df[(df['colName']==0) | (df['colName']==1)].index
df = df.loc[indexer,:]
</code></pre>

python pandas dataframe