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 .rename and .rename_index for doing the same operation, that is when the index or mapper argument (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).

Comment From: gfyoung

Not quite an enhancement but totally onboard with making a cleaner, simpler API.

Comment From: jreback

this issue is duplicated by much discussion already, pls comment on the existing issues: #14829

xref issues:

12392

14636

15104