Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jreback opened this issue Jun 29, 2013 · 1 comment
Closed

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

jreback opened this issue Jun 29, 2013 · 1 comment
Labels
API Design Duplicate Report Duplicate issue or pull request Enhancement Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@jreback
Copy link
Contributor

jreback commented Jun 29, 2013

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))
@jreback jreback modified the milestones: 0.15.0, 0.14.0 Feb 18, 2014
@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label Jul 6, 2018
@WillAyd
Copy link
Member

WillAyd commented Jul 6, 2018

Closing in favor of #21645

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Duplicate Report Duplicate issue or pull request Enhancement Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants