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


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

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

Pandas TimedeltaIndex.identical()函數確定兩個Index對象是否包含相同的元素。如果所考慮的兩個對象包含相同的元素,則該函數返回True,否則該函數返回False。

注意:它類似於equals,但是請檢查其他可比較的屬性是否相等。


用法: TimedeltaIndex.identical(other)

參數:
other:其他物件

返回:布爾值

範例1:采用TimedeltaIndex.identical()用於檢查兩個給定的TimedeltaIndex對象中包含的元素是否相同的函數。

# importing pandas as pd 
import pandas as pd 
  
# Create the first TimedeltaIndex object 
tidx1 = pd.TimedeltaIndex(start ='1 days 06:05:01.000030', periods = 5, 
                                              freq ='D', name ='Koala') 
  
# Create the second TimedeltaIndex object 
tidx2 = pd.TimedeltaIndex(start ='1 days 06:05:01.000030', periods = 5, 
                                             freq ='D', name ='Koala') 
  
# Print the first and second TimedeltaIndex object 
print(tidx1, '\n', tidx2)

輸出:



現在我們將使用TimedeltaIndex.identical()用於檢查tidx1和tidx2中包含的值是否相同的函數。

# find if the elements are identical in tidx1 and tidx2 
tidx1.identical(tidx2)

輸出:

正如我們在輸出中看到的,TimedeltaIndex.identical()函數已返回True指示兩個對象彼此相同。

範例2:采用TimedeltaIndex.identical()用於檢查兩個給定的TimedeltaIndex對象中包含的元素是否相同的函數。

# importing pandas as pd 
import pandas as pd 
  
# Create the TimedeltaIndex object 
tidx1 = pd.TimedeltaIndex(data =['1 days 02:00:00', '1 days 06:05:01.000030',  
                                 '1 days 02:00:00', '1 days 02:00:00', 
                                           '21 days 06:15:01.000030']) 
  
# Create the second TimedeltaIndex object 
tidx2 = pd.TimedeltaIndex(data =['06:05:01.000030', '+23:59:59.999999',  
                          '22 day 2 min 3us 10ns', '+12:19:59.999999']) 
  
# Print the first and second TimedeltaIndex object 
print(tidx1, '\n', tidx2)

輸出:


現在我們將使用TimedeltaIndex.identical()函數檢查tidx1和tidx2中包含的值是否相同。

# find if the elements are identical in tidx1 and tidx2 
tidx.identical(tidx2)

輸出:

正如我們在輸出中看到的,TimedeltaIndex.identical()函數已返回False指示兩個對象彼此不相同。



相關用法


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