-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Have the possibility for Series.unique() to return a Series rather than an array #1923
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
Comments
Well it's a good question. I guess the main issue is what index you should assign (default 0 to N-1 would be the only reasonable one probably, otherwise the index values where the unique values occurred). |
In data lunedì 17 settembre 2012 05:35:34, Wes McKinney ha scritto:
I don't have strong opinions on either, any would be a very good improvement Luca Beltrame - KDE Forums team |
I think the second option (indices of the unique entries) would be helpful On Mon, Sep 17, 2012 at 3:21 PM, Luca Beltrame [email protected]:
|
I agree it would be helpful. But more expensive to compute. Have to think about it |
I don't think unique should return a Series with a meaningless integer index, seems harmful/confusing if the original Series also had an integer index. |
like how about this:
|
yeah, exactly what I was thinking |
s.unique() --> keep method as it is, a faster alternative to np.unique() --- no index Add drop_duplicates() to Series?: |
That's not a bad idea either |
Maybe drop_duplicates to get first or last and then a separate method to get a reverse mapping of all indices for each unique value? |
See |
At the risk of appearing to re-open something that is dead, I thought I'd just summarize for any newcomers to this page:
So, if you wanted to do something like the OP and wanted to keep the indices, you'd perform:
( |
In case anyone feels like writing a PR, the |
I admit I haven't looked at the code so there may be reasons for this, but I've found myself in the need of squeezing out duplicates from a Series but keeping the results as a Series.
Series.unique() however returns an array, so in my code I have to construct a Series twice:
Is this by design? If so, feel free to close this bug.
The text was updated successfully, but these errors were encountered: