Disjoint set of records from two pandas DataFrames
Question: Is there an easy way to find the disjoint set of records (what would be left
on each of the two original dataframes that is not included in the resulting
inner join) between two pandas dataframes based on a MultiIndex?

Am I missing something rather obvious or do I have to spend some time
implementing this kind of functionality myself?

I attempted to do this by finding the symmetric difference between the set of
muliIndex keys of the two dataframes, but this has proved difficult. I have
been struggling to get this to work. My other option, which seems like it
might be a bit easer is to add a dummy column of integers that can act as a
different single index that is preserved even after I do the multiIndex merge
so I that I can use the python set operators on this de facto single key.

[Note that this is related to but slightly different than this question
because this merge is not based on a MultiIndex object, but on the values in
columns of the dataframe: [How do I do a SQL style disjoint or set difference
on two Pandas DataFrame
objects?](http://stackoverflow.com/questions/14405975/how-do-i-do-a-sql-style-
disjoint-or-set-difference-on-two-pandas-dataframe-objec) ]


Answer: I think your approach of finding the symmetric difference is the way to go.

    
    
    In [97]: from numpy import random
    
    In [98]: arrays1 = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
       ....:           ['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two']]
    
    
    In [99]: arrays2 = [['bar', 'baz', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'], [
       ....: 'one', 'one', 'two', 'three', 'one', 'two', 'one', 'three']]
    
    
    In [100]: tuples1 = zip(*arrays1)
    
    In [101]: tuples2 = zip(*arrays2)
    
    In [102]: index1 = MultiIndex.from_tuples(tuples1, names=['first', 'second'])
    
    In [103]: index2 = MultiIndex.from_tuples(tuples2, names=['first', 'second'])
    
    In [104]: df1 = pd.DataFrame(random.randn(8, 2), index=index1)
    
    In [105]: df2 = pd.DataFrame(random.randn(8, 2), index=index2)
    
    In [106]: df1
    Out[106]: 
                         0         1
    first second                    
    bar   one     0.613378 -0.400247
    baz   one    -3.005834  0.004879
          two     0.066539 -0.289100
          three  -0.020099  0.644226
    foo   one    -0.461458 -1.621812
          two     0.286655  0.110588
    qux   one     0.363648 -0.271281
          three   1.707787 -1.832602
    
    In [107]: df2
    Out[107]: 
                         0         1
    first second                    
    bar   one    -1.010482 -0.023373
    baz   one    -0.040335  1.553905
          two    -0.080283 -0.571686
          three  -0.985722 -0.795481
    foo   one     0.623122  2.124316
          two    -0.493333 -0.343462
    qux   one    -1.346753 -1.343945
          three  -0.053497 -0.382402
    
    In [108]: sym_diff = (df1.index - df2.index).union(df2.index - df1.index)
    
    In [109]: sym_diff
    Out[109]: 
    MultiIndex
    [(u'baz', u'three'), (u'qux', u'three')]
    

I'm not sure why there isn't a symmetric difference method on MultiIndex.

