Saturday, February 14, 2026
HomeLanguagesPython | Pandas TimedeltaIndex.get_slice_bound

Python | Pandas TimedeltaIndex.get_slice_bound

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_slice_bound() function calculate slice bound that corresponds to given label. The function return leftmost (one-past-the-rightmost if side==’right’) position of given label.

Syntax : TimedeltaIndex.get_slice_bound(label, side, kind)

Parameters :
label : object
side : {‘left’, ‘right’}
kind : {‘ix’, ‘loc’, ‘getitem’}

Return : int

Example #1: Use TimedeltaIndex.get_slice_bound() function to find the left slice bound of a value in 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_slice_bound() function to find the left slice bound of ‘1 days 02:00:00’.




# find the left slice bound for passed value
tidx.get_slice_bound('1 days 02:00:00', side ='left', kind ='loc')


Output :

As we can see in the output, the TimedeltaIndex.get_slice_bound() function has returned 3 as the slice bound for the passed value in the given TimedeltaIndex object.
 
Example #2: Use TimedeltaIndex.get_slice_bound() function to find the left slice bound of a value in the given TimedeltaIndex object.




# importing pandas as pd
import pandas as pd
  
# Create the TimedeltaIndex object
tidx = pd.TimedeltaIndex(data =['06:05:01.000030', '3 days 06:05:01.000030'
                                '22 day 2 min 3us 10ns', '+23:59:59.999999',
                             '13 days 06:05:01.000030', '+12:19:59.999999'])
  
# Print the TimedeltaIndex object
print(tidx)


Output :

Now we will use the TimedeltaIndex.get_slice_bound() function to find the left slice bound of ’13 days 06:05:01.000030′.




# find the left slice bound for passed value
tidx.get_slice_bound('13 days 06:05:01.000030', side ='left', kind ='loc')


Output :

As we can see in the output, the TimedeltaIndex.get_slice_bound() function has returned 4 as the slice bound for the passed value in the given TimedeltaIndex object.

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

Most Popular

Dominic
32504 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6880 POSTS0 COMMENTS
Nicole Veronica
12003 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12097 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6965 POSTS0 COMMENTS
Umr Jansen
6954 POSTS0 COMMENTS