Python | Pandas TimedeltaIndex.get_slice_bound



TimedeltaIndex.get_slice_bound() Pandas TimedeltaIndex.get_slice_bound() calculates the slice boundary that matches the given label … The function returns the far left (one far right if side == & # 39; right & # 39;) position of the 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 () to find the left slice boundary of the value in a given TimedeltaIndex.

# 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 TimedeltaIndex object

print (tidx)

Output:

Now we will use Use TimedeltaIndex.get_slice_bound () to find the left slice boundary & # 39; 1 days 02: 00: 00 & # 39 ;.

# find the left slice bound to the passed value

tidx.get_slice_bound ( `1 days 02: 00: 00` , side = `left` , kind = `loc` )

Output:

As we can see in the output, TimedeltaIndex.get_slice_bound () returned 3 as slice boundaries for the passed value in this TimedeltaIndex object.

Example # 2: Use Call TimedeltaIndex.get_slice_bound () to find the left slice boundary of the value in this TimedeltaIndex.

# import pandas as pd

import pandas as pd

 
# Create 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 TimedeltaIndex object

print (tidx)

Output:

Now we will use TimedeltaIndex.get_slice_bound () to find the border of the left slice “13 days 06: 05: 01.000030”.

# find the left slice anchored to passed value

tidx.get_slice_bound ( `13 days 06: 05: 01.000 030` , side = `left` , kind = `loc` )

Output:

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