Sunday, February 22, 2026
HomeLanguagesPython | Pandas TimedeltaIndex.get_level_values

Python | Pandas TimedeltaIndex.get_level_values

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas TimedeltaIndex.get_level_values() function return an Index of values for requested level, equal to the length of the index.

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() function to find all the values present in the 0th level of the given TimedeltaIndex object.




# importing pandas as pd
import pandas as pd
  
# Create the 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 TimedeltaIndex object
print(tidx)


Output :

Now we will use the TimedeltaIndex.get_level_values() function to find all the values in 0th level




# print values in 0th level
tidx.get_level_values(0)


Output :

As we can see in the output, the TimedeltaIndex.get_level_values() function has returned all the values present in the 0th level of tidx object. This object has only one level.
 
Example #2: Use MultiIndex.get_level_values() function to find all the values present in the 1st level of the given MultiIndex object.




# importing pandas as pd
import pandas as pd
  
# Create the MultiIndex object
midx = pd.MultiIndex.from_arrays((['AB', 'BC', 'CD', 'DE'], 
                                  ['EF', 'FG', 'GH', 'HI']))
  
# Print the MultiIndex object
print(midx)


Output :

Now we will use the MultiIndex.get_level_values() function to find all values in the 1st level




# print values in 1st level
midx.get_level_values(1)


Output :

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS