Pandas Series: set_axis() function

Series-set_axis() function

The set_axis() function is used to assign desired index to given axis.
Indexes for column or row labels can be changed by assigning a list-like or Index.
Changed in version 0.21.0: The signature is now labels and axis, consistent with the rest of pandas API. Previously, the axis and labels arguments were respectively the first and second positional arguments.


Series.set_axis(self, labels, axis=0, inplace=None)
Pandas Series set_axis image


Name Description Type/Default Value Required / Optional
labels The values for the new index. list-like, Index Required
axis The axis to update. The value 0 identifies the rows, and 1 identifies the columns. {0 or ‘index’, 1 or ‘columns’}
Default Value: 0
inplace Whether to return a new %(klass)s instance. bool
Default Value: None

Returns: renamed - %(klass)s or None An object of same type as caller if inplace=False, None otherwise.


Download the Pandas Series Notebooks from here.

Previous: Random items from an axis of Pandas object
Next: Series-take() function

Share this Tutorial / Exercise on : Facebook and Twitter