Python是进行数据分析的一种出色语言,主要是因为以数据为中心的python软件包具有奇妙的生态系统。 Pandas是其中的一种,使导入和分析数据更加容易。
 Pandas  dataframe.equals()函数用于确定所考虑的两个数据帧对象是否相等。不像dataframe.eq()方法,运算结果是一个标量布尔值,指示 DataFrame 对象是否相等。
用法: DataFrame.equals(other)
参数:
other: DataFrame 
返回:标量:布尔值
范例1:采用equals()函数查找两个不同 DataFrame 对象之间的比较结果。
# importing pandas as pd 
import pandas as pd 
  
# Creating the first dataframe  
df1 = pd.DataFrame({"A":[1,5,7,8], 
                  "B":[5,8,4,3], 
                  "C":[10,4,9,3]}) 
  
# Creating the second dataframe 
df2 = pd.DataFrame({"A":[5,3,6,4], 
                  "B":[11,2,4,3], 
                  "C":[4,3,8,5]}) 
  
# Print the first dataframe 
df1 
  
# Print the second dataframe 
df2

让我们找到两个 DataFrame 之间的比较结果。
# To find the comparison result 
df1.equals(df2)输出:

输出为False,因为两个数据帧彼此不相等。它们具有不同的元素。
范例2:采用equals()用于测试两个 DataFrame 对象之间是否相等的函数NaN值。
注意:相同位置的NaN被认为是相等的。
# importing pandas as pd 
import pandas as pd 
  
# Creating the first dataframe 
df1 = pd.DataFrame({"A":[1,2,3], 
                  "B":[4,5,None], 
                  "C":[7,8,9]}) 
  
# Creating the second dataframe 
df2 = pd.DataFrame({"A":[1,2,3], 
                  "B":[4,5,None], 
                  "C":[7,8,9]}) 
  
# Print the first dataframe 
df1 
  
# Print the second dataframe 
df2

让我们对两个 DataFrame 执行比较操作。
# To find the comparison between two dataframes 
df1.equals(df2)输出:

输出标量布尔值。 True表示两个数据帧在相应的单元格中具有相等的值。
相关用法
- 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 dataframe.equals()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
