pandas equivalent of SELECT * FROM table WHERE column1=column2
<p>What is the pandas equivalent of 'SELECT * FROM table WHERE column1=column2'?</p>

<p>You have a dataframe, two columns with values. You want all rows where the numbers in both columns are the same. What's the code for that?</p>

<pre><code>dataframe:
column1   column2
a        b
b        a
c        c
d        d
a        b
a        b

The result I want:
column1   column2
c        c
d        d
</code></pre>

<p>Thank you.</p>

<p>In this case, you will use something from Pandas called Masking</p>

<p>Basically, DataFrame[condition, on a column or the entire dataframe itself] returns a DataFrame where the condition is True.</p>

<pre><code>import pandas as pd
import numpy as np

data = {'a':np.random.randint(0, 10, 100),
       'b':np.random.randint(0, 10, 100)}

df = pd.DataFrame(data)
df[df.a==df.b]
</code></pre>

python pandas