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几个月后,我可以提出自己问题的答案。
用于比较两个数组使用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。