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()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
