pandas 1.4.2

ParametersReturns
set_axis(self, labels, axis: 'Axis' = 0, inplace: 'bool' = False)

Indexes for column or row labels can be changed by assigning a list-like or Index.

Parameters

labels : list-like, Index

The values for the new index.

axis : {0 or 'index', 1 or 'columns'}, default 0

The axis to update. The value 0 identifies the rows, and 1 identifies the columns.

inplace : bool, default False

Whether to return a new DataFrame instance.

Returns

renamed : DataFrame or None

An object of type DataFrame or None if inplace=True .

Assign desired index to given axis.

See Also

DataFrame.rename_axis

Alter the name of the index or columns.

Examples

>>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})

Change the row labels.

>>> df.set_axis(['a', 'b', 'c'], axis='index')
   A  B
a  1  4
b  2  5
c  3  6

Change the column labels.

>>> df.set_axis(['I', 'II'], axis='columns')
   I  II
0  1   4
1  2   5
2  3   6

Now, update the labels inplace.

>>> df.set_axis(['i', 'ii'], axis='columns', inplace=True)
>>> df
   i  ii
0  1   4
1  2   5
2  3   6
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/frame.py#4742
type: <class 'function'>
Commit: