-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Description
This was suggested by @MaximilianR here, but @jorisvandenbossche (rightly) proposed to discuss separately.
This is related to the discussion on .rename and .rename_axis's signatures (see above), but touches a different issue. Currently, these two functions are confusing not just because they do the same thing, but also because they (each) do two different things (renaming axis/object name, and relabeling), and because they do not do the most obvious thing (relabeling by passing a list-like - since a list-like is assumed to refer to multiple names for a MultiIndex' levels).
My proposal is the following:
- add a new method
.relabel, which changes the content of the axis, as in
df.relabel(['l1', 'l2', 'l3']) # changes df.index labels - assuming df.index is flat
df.relabel([['l1a', 'l1b', 'l1c'], [...], [...]]) # changes df.index labels - assuming df.index has 3 levels
df.relabel(a_dict) # again, changes the index labels, analogously to what df.rename(a_dict) currently does- deprecate the use of
.renameand.rename_indexfor doing the same operation, that is when theindexormapperargument (respectively) is a callable or dict-like; keep them (or, even better, keep one and deprecate the other) for changing only index names
Whether the signature of .relabel should follow the axis= or index=, column= standard will depend from the outcome of the discussion about rename and rename_index (#12392).