w3resource

Pandas Series: rename() function

Alter Series index in Pandas

The rename() function is used to alter Series index labels or name.

Function / dict values must be unique (1-to-1). Labels not contained in a dict / Series will be left as-is. Extra labels listed don’t throw an error.

Alternatively, change Series.name with a scalar value.

Syntax:

Series.rename(self, index=None, **kwargs)
Pandas Series rename image

Parameters:

Name Description Type/Default Value Required / Optional
index dict-like or functions are transformations to apply to the index. Scalar or hashable sequence-like will alter the Series.name attribute. scalar, hashable sequence, dict-like or function optional
copy Whether to copy underlying data. bool
Default Value: True
Required
inplace Whether to return a new Series. If True then value of copy is ignored. bool
Default Value: False
Required
level In case of a MultiIndex, only rename labels in the specified level. int or level name
Default Value: None
Required

Returns: Series
Series with index labels or name altered.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts