`assert_frame_equal`和`equals`有什么区别 [英] What is the difference between `assert_frame_equal` and `equals`

查看:388
本文介绍了`assert_frame_equal`和`equals`有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇地发现了assert_frame_equalequal之间的区别. 两者都用于检查两个数据的相等性.它适用于assert_series_equalassert_index_equal.那么equals和测试函数之间有什么区别?

I'm curious to find the difference between assert_frame_equal and equal. Both are for checking the equality of two data. It applies for assert_series_equal and assert_index_equal. So what is the difference between equals and testing functions?

到目前为止,我发现测试功能为比较值(如check_dtpye选项等)提供了更多的灵活性,并且不同于返回值,这是它们之间的唯一区别吗?

So far I found was testing functions gives little more flexibility to compare the values, like check_dtpye options etc., and differs from returning values Is this the only difference between them?

否则,何时应该使用equals方法以外的测试功能?

or otherwise, When Should I use testing functions other than equals method?

df1=pd.DataFrame({'a':[1,2,3,4,5],'b':[6,7,8,9,10]})
df2=pd.DataFrame({'a':[1,2,3,4,5],'b':[6,7,8,9,10]})
pd.testing.assert_frame_equal(df1,df2)
print df1.equals(df2)

pd.testing.assert_series_equal(df1['a'],df2['a'])
print df1['a'].equals(df2['a'])

pd.testing.assert_index_equal(df1.index,df2.index)
print df1.index.equals(df2.index)

推荐答案

DataFrame.equals 只是返回布尔值True/False.

DataFrame.equals simply returns a boolean True/False.

df1.equals(df2)
# True

df1.equals(pd.DataFrame())
# False    

pd.testing中定义的其他功能也是如此,这些功能用于开发

This is also the case for the other functions defined in pd.testing, which are used to develop unit tests for pandas code.

这篇关于`assert_frame_equal`和`equals`有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆