ENH: symmetric_difference for Index · Issue #5543 · pandas-dev/pandas (original) (raw)
I've had to use this a few times, maybe some other people could use it too.
At least for unique indices, the symmetric difference should be equivalent to (df1.index - df2.index).union(df2.index - df1.index)
. Example:
In [54]: df1 = pd.DataFrame([1,2,3,4], index=['a', 'b', 'c', 'd'])
In [55]: df1 Out[55]: 0 a 1 b 2 c 3 d 4
In [56]: df2 = pd.DataFrame([5, 6, 7, 8], index=['a', 'd', 'e', 'f'])
In [57]: df2 Out[57]: 0 a 5 d 6 e 7 f 8
In [58]: (df1.index - df2.index).union(df2.index - df1.index) Out[58]: Index([u'b', u'c', u'e', u'f'], dtype='object')
I'll need to look into how would work for
- Indicies with duplicates
- MultiIndexes