📜  Python| Pandas TimedeltaIndex.intersection

📅  最后修改于: 2022-05-13 01:55:36.212000             🧑  作者: Mango

Python| Pandas TimedeltaIndex.intersection

Python是一种用于进行数据分析的出色语言,主要是因为以数据为中心的Python包的奇妙生态系统。 Pandas就是其中之一,它使导入和分析数据变得更加容易。

Pandas TimedeltaIndex.intersection()函数返回一个新索引,其中包含两个索引共有的索引元素。这是 TimedeltaIndex 对象的专用交集。它可能比 Index.intersection 快得多。

示例 #1:使用 TimedeltaIndex.intersection()函数查找两个 TimedeltaIndex 对象的交集。

Python3
# importing pandas as pd
import pandas as pd
 
# Create the first TimedeltaIndex object
tidx1 = pd.TimedeltaIndex(start ='11 days 22:11:12.001124', periods = 5,
                                          freq ='T', name ='New_object')
 
# Create the second TimedeltaIndex object
tidx2 = pd.TimedeltaIndex(start ='11 days 22:14:12.001124', periods = 5,
                                          freq ='T', name ='New_object')
 
# Print the first and second TimedeltaIndex object
print(tidx1, '\n', tidx2)


Python3
# find the intersection
tidx1.intersection(tidx2)


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


Python3
# find the intersection
tidx1.intersection(tidx2)


输出 :

现在我们将使用 TimedeltaIndex.intersection()函数来查找两个对象的交集

Python3

# find the intersection
tidx1.intersection(tidx2)

输出 :

正如我们在输出中看到的,TimedeltaIndex.intersection()函数返回了一个对象,该对象仅包含 tidx1 和 tidx2 共有的元素。示例 #2:使用 TimedeltaIndex.intersection()函数查找两个 TimedeltaIndex 对象的交集。

Python3

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

输出 :

现在我们将使用 TimedeltaIndex.intersection()函数来查找两个对象的交集

Python3

# find the intersection
tidx1.intersection(tidx2)

输出 :

正如我们在输出中看到的,TimedeltaIndex.intersection()函数返回了一个对象,该对象仅包含 tidx1 和 tidx2 共有的元素。