Python是進行數據分析的一種出色語言,主要是因為以數據為中心的python軟件包具有奇妙的生態係統。 Pandas是其中的一種,使導入和分析數據更加容易。
 Pandas  Index.equals()函數確定兩個Index對象是否包含相同的元素。如果它們包含相同的元素,則函數返回True否則函數返回False表示兩個索引中包含的值不同。
用法: Index.equals(other)
參數:
Other:指數
返回:布爾值
範例1:采用Index.equals()檢查兩個索引是否包含相同元素的函數
# importing pandas as pd 
import pandas as pd 
  
# Creating the first Index 
idx1 = pd.Index(['Labrador', 'Beagle', 'Labrador', 'Lhasa', 'Husky', 'Beagle']) 
  
# Creating the second Index 
idx2 = pd.Index(['Labrador', 'Beagle', 'Pug', 'Lhasa', 'Husky', 'Pitbull']) 
  
# Print the first and second Index 
print(idx1, "\n", idx2)輸出:


讓我們檢查兩個索引是否相等。
# Checking the equality of the two Indexes 
idx1.equals(idx2)輸出:

正如我們在輸出中看到的,Index.equals()函數已返回False指示索引不相等。
範例2:采用Index.equals()函數檢查兩個索引是否相等。
# importing pandas as pd 
import pandas as pd 
  
# Creating the first Index 
idx1 = pd.Index(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
                 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']) 
  
# Creating the second Index 
idx2 = pd.Index(['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 
                 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']) 
  
# Print the first and second Index 
print(idx1, "\n", idx2)輸出:


讓我們檢查兩個指數是否相等。
# test the equality 
idx1.equals(idx2)輸出:

該函數已返回True指示兩個索引彼此相等。
相關用法
- Python pandas.map()用法及代碼示例
- Python Pandas Timestamp.tz用法及代碼示例
- Python Pandas Series.str.contains()用法及代碼示例
- Python Pandas dataframe.std()用法及代碼示例
- Python Pandas Timestamp.dst用法及代碼示例
- Python Pandas dataframe.sem()用法及代碼示例
- Python Pandas DataFrame.ix[ ]用法及代碼示例
- Python Pandas.Categorical()用法及代碼示例
- Python Pandas.apply()用法及代碼示例
- Python Pandas TimedeltaIndex.contains用法及代碼示例
- Python Pandas Timestamp.now用法及代碼示例
- Python Pandas Series.str.pad()用法及代碼示例
- Python Pandas Series.take()用法及代碼示例
- Python Pandas dataframe.all()用法及代碼示例
- Python Pandas series.str.get()用法及代碼示例
注:本文由純淨天空篩選整理自Shubham__Ranjan大神的英文原創作品 Python | Pandas Index.equals()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
