Skip to content

ENH: symmetric_difference for Index #5543

Closed
@TomAugspurger

Description

@TomAugspurger

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignEnhancementIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions