當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Pandas TimedeltaIndex.get_slice_bound用法及代碼示例

Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。

Pandas TimedeltaIndex.get_slice_bound()函數計算與給定標簽對應的切片範圍。該函數返回給定標簽的最左位置(如果side =='right',則為one-past-the-rightmost)位置。

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

參數:
label: Object
side:{'左右'}
kind:{“ ix”,“ loc”,“ getitem”}

返回:整型

範例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)

輸出:

現在我們將使用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')

輸出:

正如我們在輸出中看到的,TimedeltaIndex.get_slice_bound()函數已返回3作為給定TimedeltaIndex對象中傳遞的值的切片邊界。

範例2:采用TimedeltaIndex.get_slice_bound()函數在給定的TimedeltaIndex對象中查找值的左切片邊界。

輸出:

正如我們在輸出中看到的,TimedeltaIndex.get_slice_bound()函數已返回4作為給定TimedeltaIndex對象中傳遞的值的切片邊界。



相關用法


注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas TimedeltaIndex.get_slice_bound。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。