pandas 1.4.2

NotesParametersReturnsBackRef
get_level_values(self, level)

Length of returned vector is equal to the length of the index.

Notes

If the level contains missing values, the result may be casted to float with missing values specified as NaN . This is because the level is converted to a regular Index .

Parameters

level : int or str

level is either the integer position of the level in the MultiIndex, or the name of the level.

Returns

values : Index

Values is a level of this MultiIndex converted to a single Index (or subclass thereof).

Return vector of label values for requested level.

Examples

Create a MultiIndex:

This example is valid syntax, but we were not able to check execution
>>> mi = pd.MultiIndex.from_arrays((list('abc'), list('def')))
... mi.names = ['level_1', 'level_2']

Get level values by supplying level as either integer or name:

This example is valid syntax, but we were not able to check execution
>>> mi.get_level_values(0)
Index(['a', 'b', 'c'], dtype='object', name='level_1')
This example is valid syntax, but we were not able to check execution
>>> mi.get_level_values('level_2')
Index(['d', 'e', 'f'], dtype='object', name='level_2')

If a level contains missing values, the return type of the level maybe casted to float .

This example is valid syntax, but we were not able to check execution
>>> pd.MultiIndex.from_arrays([[1, None, 2], [3, 4, 5]]).dtypes
level_0    int64
level_1    int64
dtype: object
This example is valid syntax, but we were not able to check execution
>>> pd.MultiIndex.from_arrays([[1, None, 2], [3, 4, 5]]).get_level_values(0)
Float64Index([1.0, nan, 2.0], dtype='float64')
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.indexes.base.Index._get_level_values

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/indexes/multi.py#1650
type: <class 'function'>
Commit: