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.


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


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 DataFrame Notebooks from here.

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

Follow us on Facebook and Twitter for latest update.