6

UPDATE: To compare "close" and not "equal" use "check_exact=False" in the call to "assert_frame_equal" as detailed here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.testing.assert_frame_equal.html.

Original question: A Pandas dataframe contains N columns of floats.

I want to check whether the elements in each possible pair of columns are equal (so check if all elements in column i are close, within some tolerance I mean, to all elements in column j).

I could iterate and use np.allclose(...), but I wonder if there is a better (read: built-in) way of doing this in Pandas, ideally something where I can use the column labels?

I am thinking: df.allclose(['a', 'b', 'c']) kind of thing...

Jesper - jtk.eth
  • 7,026
  • 11
  • 36
  • 63
  • 1
    See [this](http://stackoverflow.com/questions/19917545/comparing-two-pandas-dataframes-for-differences) question, if it helps. [This blog post](https://penandpants.com/2014/10/07/testing-with-numpy-and-pandas/) says that by default it uses "an allclose-like comparison" – vmg Jun 27 '16 at 16:06
  • @ostrokach Perfect, also, note that the "check_exact" option is needed in the call to assert_frame_equal to answer my question. – Jesper - jtk.eth Oct 31 '17 at 22:02

0 Answers0