Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
Pandas TimedeltaIndex.symmetric_difference()
函數計算兩個Index對象的對稱差。如果可以排序,則進行排序。對於給定的一對TimedeltaIndex對象idx1
和idx2
,symmetric_difference包含出現在任一idx1
或者idx2
但不是兩者兼而有之。等效於創建的索引idx1.difference(idx2)
或者idx2.difference(idx1)
刪除重複項。
用法: TimedeltaIndex.symmetric_difference(other, result_name=None)
參數:
other:索引或array-like
result_name:力量
返回:symmetric_difference:索引
範例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 seccond 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)
輸出:
現在我們將使用TimedeltaIndex.symmetric_difference()
函數查找對稱差異。
# find the symmetric difference
tidx1.symmetric_difference(tidx2)
輸出:
正如我們在輸出中看到的,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)
輸出:
現在我們將使用TimedeltaIndex.symmetric_difference()
函數查找對稱差異。
# find the symmetric difference
tidx1.symmetric_difference(tidx2)
輸出:
正如我們在輸出中看到的,TimedeltaIndex.symmetric_difference()
函數已返回一個新對象,該對象僅包含兩個對象都不通用的元素。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Series.str.len()用法及代碼示例
- Python Pandas.factorize()用法及代碼示例
- Python Pandas TimedeltaIndex.name用法及代碼示例
- Python Pandas dataframe.ne()用法及代碼示例
- Python Pandas Series.between()用法及代碼示例
- Python Pandas DataFrame.where()用法及代碼示例
- Python Pandas Series.add()用法及代碼示例
- Python Pandas.pivot_table()用法及代碼示例
- Python Pandas Series.mod()用法及代碼示例
- Python Pandas Dataframe.at[ ]用法及代碼示例
- Python Pandas Dataframe.iat[ ]用法及代碼示例
- Python Pandas.pivot()用法及代碼示例
- Python Pandas dataframe.mul()用法及代碼示例
- Python Pandas.melt()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas TimedeltaIndex.symmetric_difference()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。