Skip to content

API: provide a better way of doing np.unique(return_inverses=True) #4087

Closed
@jreback

Description

@jreback

The numpy way

In [183]: x
Out[183]: 
   one two
0    1   a
2    2   c
3    3   d
4    4   d
5    5   d

In [184]: np.unique(x['two'].values,return_inverse=True)
Out[184]: (array(['a', 'c', 'd'], dtype=object), array([0, 1, 2, 2, 2]))

The pandas way - maybe provide a better API to this
maybe: uniques, indexer = Index(x['two']).get_uniques() ??

In [186]: uniques = x['two'].unique()

In [187]: uniques
Out[187]: array(['a', 'c', 'd'], dtype=object)

In [188]: Index(uniques).get_indexer_non_unique(x['two'])
Out[188]: (Int64Index([0, 1, 2, 2, 2], dtype=int64), array([], dtype=int64))

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDuplicate ReportDuplicate issue or pull requestEnhancementIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions