title: Conditional testing and comparison of two columns in a pandas dataframe
body: <p>I am trying to perform a conditional check on a dataframe with two columns as follows: content of either column cannot be in the other column unless both values are equal - there can be no instance where a value is present in both columns and the values are not equal. </p>
  
  <p>In the e.g. below, the condition is met. Though alternahaircare.com is in both columns - domain and credit_domain, the only case where that happens, both values are equal.</p>
  
  <pre><code>Out[198]: df
                              domain               credit_domain
  2              alternahaircare.com         alternahaircare.com
  3    alternahaircare.myshopify.com         alternahaircare.com
  4         shop.alternahaircare.com         alternahaircare.com
  5                 americancrew.com            americancrew.com
  </code></pre>
  
  <p>Below are two modified examples of the above where the conditions I want to satisfy is not met: </p>
  
  <p>In this one, you can see that there is a row where domain = alternahaircare and credit_domain = americancrew.com. This is wrong - now alternahaircare.com occurs in both columns but there is an instance where the value in the credit_domain column does not match domain column.</p>
  
  <pre><code>Out[199]: df
                              domain               credit_domain
  2              alternahaircare.com            americancrew.com
  3    alternahaircare.myshopify.com         alternahaircare.com
  4         shop.alternahaircare.com         alternahaircare.com
  5                 americancrew.com            americancrew.com
  </code></pre>
  
  <p>The below instance is also wrong - does not meet the conditions i want to satisfy. Though there is an instance of alternahaircare.com == alternahaircare.com, there is also an instance of alternahaircare.com being assigned to a value that is not itself i.e. americacrew.com</p>
  
  <pre><code>Out[198]: df
                              domain               credit_domain
  2              alternahaircare.com         alternahaircare.com
  3    alternahaircare.myshopify.com         alternahaircare.com
  4         shop.alternahaircare.com         alternahaircare.com
  5              alternahaircare.com            americancrew.com
  </code></pre>
  
  <p>The second of of these problem can be addressed easily by checking the count of domain values and identifying anything that occurs twice. </p>
  
  <p>The first problem has me confused. My approach was to identify the potential problem rows and then try using a groupby and a conditional statement:</p>
  
  <pre><code>potential_error_rows = df[df.credit_domain.isin([x for x in df.credit_domain.tolist() if x in df.domain.tolist()])]
  </code></pre>
  
  <p>Couldn't think of what to do beyond this!</p>