Python Pandas - 確定兩個索引物件是否相等
若要確定兩個索引物件是否相等,請使用 equals() 方法。
首先,匯入所需的庫 −
import pandas as pd
建立 index1 和 index2 −
index1 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55]) index2 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55])
顯示 index1 和 index2 −
print("Pandas Index1...\n",index1)
print("Pandas Index2...\n",index2)檢查兩個索引物件是否相等 −
index1.equals(index2)
示例
以下是程式碼 −
import pandas as pd
# Creating index1 and index2
index1 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55])
index2 = pd.Index([15, 25, 55, 10, 100, 70, 35, 40, 55])
# Display the index1 and index2
print("Pandas Index1...\n",index1)
print("Pandas Index2...\n",index2)
print("\nAre these two Index objects equal?\n",index1.equals(index2))輸出
將生成以下程式碼 −
Pandas Index1... Int64Index([15, 25, 55, 10, 100, 70, 35, 40, 55], dtype='int64') Pandas Index2... Int64Index([15, 25, 55, 10, 100, 70, 35, 40, 55], dtype='int64') Are these two Index objects equal? True
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP