title: How to replace values in data frame with 2-level columns based on condition in Python?
body: <p>I use Python 3.6.1. Here is my data frame myDF I want to manipulate values for:</p>
  
  <pre><code>    a     b          c      
      a    X1    X2   X1    X2
   0  10    .     o    o     o
   1  20    .     o    o     o
   2  30    .     o    o     o
  </code></pre>
  
  <p>As you can see there are columns 'a', 'b', 'c' on level 0, and there are columns 'a', 'X1', 'X2' on level 1.</p>
  
  <p>I need to compare whether a value in X1 is equal to a corresponding value in X2 under b/c and if so, remove the values. So the operation on the above data frame should return this:</p>
  
  <pre><code>    a     b          c      
      a    X1    X2   X1    X2
   0  10    .     o         
   1  20    .     o         
   2  30    .     o         
  </code></pre>
  
  <p>This is how to get the source data frame:</p>
  
  <pre><code>import numpy
  import pandas
  
  X1 = pandas.DataFrame(data=[[10,'.','o'],[20,'.','o'],[30,'.','o']],
                        columns=['a','b','c'])
  X2 = pandas.DataFrame(data=[[10,'o','o'],[20,'o','o'],[30,'o','o']],
                        columns=['a','b','c'])
  
  myDF = pandas.concat([X1.set_index('a'), X2.set_index('a')],
                       axis='columns', keys=['X1','X2'])
  myDF = myDF.swaplevel(axis='columns')[X1.columns[1:]]
  myDF = myDF.reset_index(col_level=1, col_fill='a')
  </code></pre>
  
  <p>What I have tried so far is:</p>
  
  <pre><code>other = myDF.xs('X1', axis=1, level=-1)
  main = numpy.where(myDF.eq(other, level=0), 'x', 'y')
  pandas.DataFrame(main, index=myDF.index, columns=myDF.columns)
  </code></pre>
  
  <p>Which gives:</p>
  
  <pre><code>   a    b          c      
     a   X1    X2   X1    X2
  0  F    T     F    T     T
  1  F    T     F    T     T
  2  F    T     F    T     T
  </code></pre>
  
  <p>And have no idea how to move forward ...</p>