w3resource

Pandas DataFrame: set_axis() function

DataFrame - 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.

Syntax:

DataFrame.set_axis(self, labels, axis=0, inplace=None)

Parameters:

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
Required
inplace  Whether to return a new %(klass)s instance. bool
Default Value: None
Required

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

Example:


Download the Pandas DataFrame Notebooks from here.

Previous: DataFrame - sample() function
Next: DataFrame - set_index() function



Follow us on Facebook and Twitter for latest update.