Python | Pandas TimedeltaIndex.get_level_values



TimedeltaIndex.get_level_values() Pandas TimedeltaIndex.get_level_values() returns the index of values ​​for the requested level equal to index length.

Syntax: TimedeltaIndex.get_level_values ​​(level)

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

Return: self, as there is only one level in the Index.

Example # 1: Use TimedeltaIndex.get_level_values ​​() to find all values ​​present at 0 level of this TimedeltaIndex object.

# import pandas as pd

import pandas as pd

  
# Create TimedeltaIndex object

tidx = pd.TimedeltaIndex (data = [ `3 days 06: 05: 01.000030` , ` 1 days 06 : 05: 01.000030`

`3 days 06: 05: 01.000030` , ` 1 days 02: 00: 00`

`21 days 06: 15: 01.000030` ])

 
# Print the object TimedeltaIndex

print (tidx)

 

Output:

Now we will use TimedeltaIndex.get_level_values ​​() to find all values ​​at level 0.

# print values ​​at level 0

tidx.get_level_values ​​( 0 )

Output:

As we can see in the output, TimedeltaIndex.get_level_values ​​() returned all values ​​present in the 0th level of the object tidx. This object has only one level.

Example # 2: Use MultiIndex.get_level_values ​​() to find all values ​​present at the 1st level of a given MultiIndex object.

# import pandas as pd

import pandas as pd

 
# Create object MultiIndex

midx = pd.MultiIndex. from_arrays (([ `AB` , ` BC` , `CD` , `DE` ], 

  [ `EF` , ` FG` , `GH` , ` HI ` ]))

  
# Print the MultiIndex object

print (midx)

Output:

We will now use MultiIndex.get_level_values ​​() to find all values ​​at level 1.

# printing values ​​at 1st level

midx.get_level_values ​​( 1 )  

Output:

As we can see in the output, MultiIndex.get_level_values ​​() returned all the values ​​present in the 1st level object midx.