2

I have two pandas data frames in which I store money amounts, i.e. decimal numbers with at most 15 significant decimal digits. Since float64 has a precision of 15 significant decimal digits, this should be lossless.

How do I compare the values of two such dataframes for equivalence up to the 15 significant decimal digits?

In short, I am looking for something like numpy.testing.assert_approx_equal - which should however take numpy arrays as arguments rather than only scalars.

Another option would be to use a rounding function that can round to a given number of significant decimal digits rather than the usual decimal places.

ebarr
  • 7,704
  • 1
  • 29
  • 40
ARF
  • 7,420
  • 8
  • 45
  • 72

1 Answers1

0

there's actually a numpy function for this:

np.allclose

definition/usage:

np.allclose(a, b, rtol=1e-05, atol=1e-08)
acushner
  • 9,595
  • 1
  • 34
  • 34
  • 1
    Thanks but I don't think this is what I am looking for: "allclose(a,b) might be different from allclose(b,a)". This is not quite right... – ARF Nov 17 '14 at 21:08
  • yeah, just set the rtol to 0.0 and that will make that not the case – acushner Nov 17 '14 at 21:10