在几种情况下比较两个熊猫的数据框是否相等

问题描述 投票:1回答:1

R中的compare包相当于Python熊猫,其中包含同名函数,可以在多个方面比较两个数据集:

  • 您可以将不同的参数传递给compare函数,以指定df1和df2之间应接受的差异。
  • 如果两个数据集相等,但是一个数据集由于覆盖更长的时间而更长,因此可以设置compare()

可能的参数的完整列表(在R中为:

short=TRUE

Python是否有类似的程序包,可以处理两个数据集之间差异和相等的不同情况。我还没有找到等效于R的compare(model, comparison, equal = TRUE, coerce = allowAll, shorten = allowAll, ignoreOrder = allowAll, ignoreNameCase = allowAll, ignoreNames = allowAll, ignoreAttrs = allowAll, round = FALSE, ignoreCase = allowAll, trim = allowAll, dropLevels = allowAll, ignoreLevelOrder = allowAll, ignoreDimOrder = allowAll, ignoreColOrder = allowAll, ignoreComponentOrder = allowAll, colsOnly = !allowAll, allowAll = FALSE) 函数。

我找到的最接近compare的是compare函数,它不如compare()宽。

python pandas dataset compare equality
1个回答
0
投票

在使用Python几个月后,我可以提出自己问题的答案。

用于比较两个数组使用numpy包中的函数。

pandas.testing.assert_frame_equal(df, expected, check_names=False)

这些功能的文档可以在numpy.array_equal(array1,array2) # test if the same shape and values numpy.array_equiv(array1,array2) # test if shape consistent and all elements equal numpy.allclose(array1,array2) # test if same shape, elements have close values 中找到。


这就是我现在所需要的,但也许对某人可能很有益:用于比较两个文本序列,请使用difflib包,该包有助于比较HTML,.txt文件等。可以阅读文档here

© www.soinside.com 2019 - 2024. All rights reserved.