-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
ENH: set_index for Series #21684
Comments
@h-vetinari : IINM, I imagine that the implementation for |
The PR discussion for this turned quite ugly. For those finding this in the future, here's a summary:
We'll see how the latter goes. |
It seems that
|
I was surprised to find that
DataFrame.set_index
has no analogue forSeries
. This is especially surprising because I remember reading in several comments here that it is strongly preferred (i.a. by @jreback) that users do not set attributes like.name
or.index
directly -- but currently, the only options to change the index on aSeries
is either that, or reconstructing withpd.Series(s, index=desired_index)
.This is relevant in many scenarios, but in case someone would like a more concrete example -- I'm currently working on having
.duplicated
be able to return an inverse forDataFrame / Series / Index
, see #21645. This inverse needs to link two different indexes -- the one of the original object, and the index of the deduplicated one. To reconstruct from the unique values, one needs exactly such a.set_index
operation, because.reindex
in itself cannot read a set of indexes and assign them to a different set of indexes in one go (xref #21685).This object obviously still has the wrong index to be equal to the original. For
DataFrames
, the reconstruction would work asunique.reindex(inv.values).set_index(inv.index)
, and consequently, this should be available forSeries
as well:Desired:
The text was updated successfully, but these errors were encountered: