pandas.Index.set_names

pandas 3.1.1 · Index objects · method

Set one or more index level names, preserving their label values.

Call syntax

Index.set_names(names, *, level=None, inplace=False)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
names Required
Positional or keyword
Hashable or a sequence of the previous or dict-like for MultiIndex

Supply explicit names for labels, fields, or levels.

level Optional
Keyword only
Default None
int, Hashable or a sequence of the previous

Choose an index level by name or integer position.

inplace Optional
Keyword only
Default False
bool

Choose whether to change the existing object. Where supported, an in-place call typically returns None.

Returns

Index or None