How to compare four columns of pandas dataframe at a time?
<p>I have one dataframe. </p>

<p><strong>Dataframe :</strong> </p>

<pre><code>   Symbol1   BB Symbol2 CC 
0         ABC    1  ABC       1
1         PQR    1  PQR       1
2         CPC    2  CPC       0
3         CPC    2  CPC       1
4         CPC    2  CPC       2
</code></pre>

<p>I want to compare <code>Symbol1</code> with <code>Symbol2</code> and <code>BB</code> with <code>CC</code>, if they are same then I want that rows only other rows must be removed from the dataframe.</p>

<p><strong>Expected Result :</strong></p>

<pre><code>Symbol1   BB Symbol2 CC 
0         ABC    1  ABC       1
1         PQR    1  PQR       1
2         CPC    2  CPC       2
</code></pre>

<p>If comparison between two rows then I'm using : </p>

<pre><code>df = df[df['BB'] == '2'].copy()
</code></pre>

<p>It will work fine.</p>

<pre><code>df = df[df['BB'] == df['offset'] and df['Symbol1'] == df['Symbol2']].copy()
</code></pre>

<p>It is giving me error.</p>

<p><strong>Error :</strong> </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>How I can compare and get expected result?</p>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing"><code>boolean indexing</code></a> and compare with <code>&amp;</code> instead <a href="http://stackoverflow.com/a/21415990/2901002"><code>and</code></a>:</p>

<pre><code>print ((df.Symbol1 == df.Symbol2) &amp; (df.BB == df.CC))
0     True
1     True
2    False
3    False
4     True
dtype: bool

print (df[(df.Symbol1 == df.Symbol2) &amp; (df.BB == df.CC)])
  Symbol1  BB Symbol2  CC
0     ABC   1     ABC   1
1     PQR   1     PQR   1
4     CPC   2     CPC   2
</code></pre>

python pandas indexing dataframe condition