📜  Python| Pandas TimedeltaIndex.symmetric_difference()

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

Python| Pandas TimedeltaIndex.symmetric_difference()

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

Pandas TimedeltaIndex.symmetric_difference()函数计算两个 Index 对象的对称差。如果可以排序,则已排序。对于给定的 TimedeltaIndex 对象 idx1 和 idx2 对,symmetric_difference 包含出现在 idx1 或 idx2 但不是同时出现的元素。等效于由 idx1.difference(idx2) 或 idx2.difference(idx1) 创建的索引,删除了重复项。

示例 #1:使用 TimedeltaIndex.symmetric_difference()函数查找两个 TimedeltaIndex 对象的对称差。

Python3
# importing pandas as pd
import pandas as pd
 
# Create the first TimedeltaIndex object
tidx1 = pd.TimedeltaIndex(data =['06:05:01.000030', '+23:59:59.999999',
                         '22 day 2 min 3us 10ns', '+23:29:59.999999',
                         '+12:19:59.999999'])
 
# Create the second TimedeltaIndex object
tidx2 = pd.TimedeltaIndex(data =['09:11:18.000030', '+23:59:59.999999',
                         '9 day 18 min 3us ', '+23:29:59.999999',
                         '+12:19:59.999999'])
 
# Print the first TimedeltaIndex object
print(tidx1)
 
# Print the second TimedeltaIndex object
print(tidx2)


Python3
# find the symmetric difference
tidx1.symmetric_difference(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 TimedeltaIndex object
print(tidx1)
 
# Print the second TimedeltaIndex object
print(tidx2)


Python3
# find the symmetric difference
tidx1.symmetric_difference(tidx2)


输出 :

现在我们将使用 TimedeltaIndex.symmetric_difference()函数来找到对称差。

Python3

# find the symmetric difference
tidx1.symmetric_difference(tidx2)

输出 :

正如我们在输出中看到的那样,TimedeltaIndex.symmetric_difference()函数返回了一个新对象,该对象仅包含两个对象不共有的元素。示例 #2:使用 TimedeltaIndex.symmetric_difference()函数查找两个 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 TimedeltaIndex object
print(tidx1)
 
# Print the second TimedeltaIndex object
print(tidx2)

输出 :

现在我们将使用 TimedeltaIndex.symmetric_difference()函数来找到对称差。

Python3

# find the symmetric difference
tidx1.symmetric_difference(tidx2)

输出 :

正如我们在输出中看到的那样,TimedeltaIndex.symmetric_difference()函数返回了一个新对象,该对象仅包含两个对象不共有的元素。