Python Pandas TimedeltaIndex.get_slice_bound

Python Pandas TimedeltaIndex.get_slice_bound

Python是一种进行数据分析的伟大语言,主要是因为以数据为中心的Python包的奇妙生态系统。Pandas就是这些包中的一个,它使导入和分析数据变得更加容易。

Pandas TimedeltaIndex.get_slice_bound()函数计算与给定标签相对应的片断边界。该函数返回给定标签的最左侧(如果side==’right’,则为最右前侧)的位置。

语法: TimedeltaIndex.get_slice_bound(label, side, kind)

参数 :
label:对象
side : {‘left’, ‘right’}
kind: {‘ix’, ‘loc’, ‘getitem’}

返回 : int

示例#1:使用TimedeltaIndex.get_slice_bound()函数来查找给定的TimedeltaIndex对象中一个值的左片边界。

# 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)

输出 :
Python Pandas TimedeltaIndex.get_slice_bound

现在我们将使用TimedeltaIndex.get_slice_bound()函数来找到’1天02:00:00’的左边片断边界。

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

输出 :
Python Pandas TimedeltaIndex.get_slice_bound
正如我们在输出中看到的,TimedeltaIndex.get_slice_bound()函数已经返回了3,作为给定的TimedeltaIndex对象中传递值的分片边界。

示例#2:使用TimedeltaIndex.get_slice_bound()函数来查找给定的TimedeltaIndex对象中一个值的左片边界。

# 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)

输出 :
Python Pandas TimedeltaIndex.get_slice_bound
现在我们将使用TimedeltaIndex.get_slice_bound()函数来找到’13天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')

输出 :
Python Pandas TimedeltaIndex.get_slice_bound
正如我们在输出中看到的,TimedeltaIndex.get_slice_bound()函数已经返回了4,作为给定的TimedeltaIndex对象中传递值的分片边界。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间