modin.pandas.Index.rename

Index.rename(name: Any, inplace: bool = False) None[source]

Alter Index or MultiIndex name.

Able to set new names without level. Defaults to returning new index. Length of names must match number of levels in MultiIndex.

Parameters:
  • name (label or list of labels) – Name(s) to set.

  • inplace (bool, default False) – Modifies the object directly, instead of creating a new Index or MultiIndex.

Returns:

The same type as the caller or None if inplace=True.

Return type:

Index or None

See also

Index.set_names

Able to set new names partially and by level.

Examples

>>> idx = pd.Index(['A', 'C', 'A', 'B'], name='score')
>>> idx.rename('grade', inplace=False)
Index(['A', 'C', 'A', 'B'], dtype='object', name='grade')
>>> idx.rename('grade', inplace=True)
Copy

Note

Native pandas only allows hashable types for names. Snowpark pandas allows name to be any scalar or list-like type. If a tuple is used for the name, the tuple itself will be the name.

For instance, >>> idx = pd.Index([1, 2, 3]) >>> idx.rename((‘a’, ‘b’, ‘c’), inplace=True) >>> idx.name (‘a’, ‘b’, ‘c’)