Python Pandas TimedeltaIndex.symmetric_difference()

Python Pandas TimedeltaIndex.symmetric_difference()

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

Pandas TimedeltaIndex.symmetric_difference()函数计算两个索引对象的对称差。如果排序是可能的,它将被排序。对于给定的一对TimedeltaIndex对象idx1和idx2,symmetric_difference包含在idx1或idx2中出现的元素,但不是同时出现。相当于由idx1.difference(idx2)或idx2.difference(idx1)创建的索引,并删除重复的内容。

语法:TimedeltaIndex.symmetric_difference(other, result_name=None)
参数 :
other:索引或数组类
result_name : str
返回 :对称性_差异 : 索引

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

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

输出 :

Python Pandas TimedeltaIndex.symmetric_difference()

Python Pandas TimedeltaIndex.symmetric_difference()

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

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

输出 :

Python Pandas TimedeltaIndex.symmetric_difference()

正如我们在输出中看到的,TimedeltaIndex.symmetric_difference()函数返回了一个新的对象,其中只包含那些不属于两个对象的元素。

例子2:使用TimedeltaIndex.symmetric_difference()函数来寻找两个TimedeltaIndex对象的对称差。

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

输出 :

Python Pandas TimedeltaIndex.symmetric_difference()

Python Pandas TimedeltaIndex.symmetric_difference()

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

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

输出 :

Python Pandas TimedeltaIndex.symmetric_difference()

正如我们在输出中看到的,TimedeltaIndex.symmetric_difference()函数返回了一个新的对象,其中只包含那些不属于两个对象的元素。

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

Pandas 日期时间

登录

注册