set_names(self, names, level=None, inplace: 'bool' = False)
Able to set new names partially and by level.
Name(s) to set.
If the index is a MultiIndex and names is not dict-like, level(s) to set (None for all levels). Otherwise level must be None.
Modifies the object directly, instead of creating a new Index or MultiIndex.
The same type as the caller or None if inplace=True
.
Set Index or MultiIndex name.
Index.rename
Able to set new names without level.
>>> idx = pd.Index([1, 2, 3, 4])This example is valid syntax, but we were not able to check execution
... idx Int64Index([1, 2, 3, 4], dtype='int64')
>>> idx.set_names('quarter') Int64Index([1, 2, 3, 4], dtype='int64', name='quarter')This example is valid syntax, but we were not able to check execution
>>> idx = pd.MultiIndex.from_product([['python', 'cobra'],This example is valid syntax, but we were not able to check execution
... [2018, 2019]])
... idx MultiIndex([('python', 2018), ('python', 2019), ( 'cobra', 2018), ( 'cobra', 2019)], )
>>> idx.set_names(['kind', 'year'], inplace=True)This example is valid syntax, but we were not able to check execution
... idx MultiIndex([('python', 2018), ('python', 2019), ( 'cobra', 2018), ( 'cobra', 2019)], names=['kind', 'year'])
>>> idx.set_names('species', level=0) MultiIndex([('python', 2018), ('python', 2019), ( 'cobra', 2018), ( 'cobra', 2019)], names=['species', 'year'])
When renaming levels with a dict, levels can not be passed.
This example is valid syntax, but we were not able to check execution>>> idx.set_names({'kind': 'snake'}) MultiIndex([('python', 2018), ('python', 2019), ( 'cobra', 2018), ( 'cobra', 2019)], names=['snake', 'year'])See :
The following pages refer to to this document either explicitly or contain code examples using this.
pandas.core.indexes.base.Index.rename
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