You can use numpy.allclose:

numpy.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)

Returns True if two arrays are element-wise equal within a tolerance.

The tolerance values are positive, typically very small numbers. The relative difference (rtol * abs(b)) and the absolute difference atol are added together to compare against the absolute difference between a and b.

numpy works well with pandas.Series objects, so if you have two of them - s1 and s2, you can simply do:

np.allclose(s1, s2, atol=...) 

Where atol is your tolerance value.

Answer from cs95 on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.equals.html
pandas.DataFrame.equals — pandas 3.0.1 documentation
Test whether two objects contain the same elements · This function allows two Series or DataFrames to be compared against each other to see if they have the same shape and elements. NaNs in the same location are considered equal
🌐
Stack Overflow
stackoverflow.com › questions › 38057870 › pandas-dataframe-allclose
python - Pandas dataframe: allclose - Stack Overflow
June 27, 2016 - See this question, if it helps. This blog post says that by default it uses "an allclose-like comparison"
🌐
GitHub
github.com › pandas-dev › pandas › issues › 9457
assert_almost_equal / equals should allow access to np.allclose · Issue #9457 · pandas-dev/pandas
February 10, 2015 - I think a good intermediate step would be to check for array equivalence and then as a the second step call np.allclose--or maybe just do this on the outset. If that fails, which it will if there are any NaNs or if the tolerance is not met, then it will use the current logic. Or we could use np.isclose to consider NaNs as equivalent. https://github.com/pydata/pandas/blob/master/pandas/src/testing.pyx#L85 ·
Top answer
1 of 4
56

Due to imprecise float comparison you can or your comparison with np.isclose, isclose takes a relative and absolute tolerance param so the following should work:

Copydf['result'] = df['actual_credit'].ge(df['min_required_credit']) | np.isclose(df['actual_credit'], df['min_required_credit'])
2 of 4
10

@EdChum's answer works great, but using the pandas.DataFrame.round function is another clean option that works well without the use of numpy.

Copydf = pd.DataFrame(  # adding a small difference at the thousandths place to reproduce the issue
    data=[[0.3, 0.4], [0.5, 0.2], [0.400, 0.401], [0.2, 0.3]],
    columns=['actual_credit', 'min_required_credit'])

df['result'] = df['actual_credit'].round(1) >= df['min_required_credit'].round(1)
print(df)
Copy   actual_credit  min_required_credit  result
0            0.3                0.400   False
1            0.5                0.200    True
2            0.4                0.401    True
3            0.2                0.300   False

You might consider using round() to more permanently edit your dataframe, depending if you desire that precision or not. In this example, it seems like the OP suggests this is probably just noise and is just causing confusion.

Copydf = pd.DataFrame(  # adding a small difference at the thousandths place to reproduce the issue
    data=[[0.3, 0.4], [0.5, 0.2], [0.400, 0.401], [0.2, 0.3]],
    columns=['actual_credit', 'min_required_credit'])
df = df.round(1)
df['result'] = df['actual_credit'] >= df['min_required_credit']
print(df)
Copy   actual_credit  min_required_credit  result
0            0.3                  0.4   False
1            0.5                  0.2    True
2            0.4                  0.4    True
3            0.2                  0.3   False
🌐
Python Data Science Handbook
jakevdp.github.io › PythonDataScienceHandbook › 03.12-performance-eval-and-query.html
High-Performance Pandas: eval() and query() | Python Data Science Handbook
result1 = df2.T[0] + df3.iloc[1] result2 = pd.eval('df2.T[0] + df3.iloc[1]') np.allclose(result1, result2) ... Other operations such as function calls, conditional statements, loops, and other more involved constructs are currently not implemented in pd.eval(). If you'd like to execute these more complicated types of expressions, you can use the Numexpr library itself. Just as Pandas has a top-level pd.eval() function, DataFrames have an eval() method that works in similar ways.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-allclose-in-python
numpy.allclose() in Python - GeeksforGeeks
December 9, 2025 - Pandas · Practice · Django · Flask · Last Updated : 9 Dec, 2025 · numpy.allclose() is a NumPy function used to check whether two arrays are approximately equal element-wise within a given tolerance.
🌐
Medium
medium.com › @sriv.srivastava › pandas-practical-examples-1-3aa663d138f0
Pandas Practical examples — 1 - Shashank Srivastava - Medium
February 22, 2022 - import pandas as pd import numpy as nps1 = pd.Series([1.0, 2.0, 3.0]) s2 = pd.Series([1.0, 2.0, 3.2]) all_equal_false = np.allclose(s1, s2, atol=0.1) all_equal_true = np.allclose(s1, s2, atol=0.3) When you run above code snippet, all_equal_false will be false while all_equal_true will be true.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 37915
ENH: should we support np.allclose for ExtensionArrays? · Issue #37915 · pandas-dev/pandas
November 17, 2020 - In [1]: import numpy as np ...: import pandas as pd ...: ...: A = pd.array([1, 2], dtype='Int64') ...: B = pd.array([1, 2], dtype='Int64') ...: np.allclose(A, B) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-01ae8e8fc321> in <module> 4 A = pd.array([1, 2], dtype='Int64') 5 B = pd.array([1, 2], dtype='Int64') ----> 6 np.allclose(A, B) <__array_function__ internals> in allclose(*args, **kwargs) ~/anaconda3/envs/pandas-dev/lib/python3.8/site-packages/numpy/core/numeric.py in allclose(a, b, rtol, atol, equal
Author   arw2019
Find elsewhere
🌐
Skytowner
skytowner.com › explore › numpy_allclose_method
NumPy | allclose method with Examples
np.allclose(np.NaN, np.NaN, equal_nan=True) True · Published by Isshin Inada · Edited by 0 others · Did you find this page useful? thumb_up · thumb_down · Comment · Citation · Ask a question or leave a feedback... thumb_up · 0 · thumb_down · 0 · chat_bubble_outline · 0 · settings · Enjoy our search · Hit / to insta-search docs and recipes! Navigation Home Blog · Contact us · Resources Python Pandas MySQL Beautiful Soup Matplotlib NumPy PySpark ·
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.testing.assert_frame_equal.html
pandas.testing.assert_frame_equal — pandas documentation
pandas.testing.assert_frame_equal(left, right, check_dtype=True, check_index_type='equiv', check_column_type='equiv', check_frame_type=True, check_names=True, by_blocks=False, check_exact=<no_default>, check_datetimelike_compat=False, check_categorical=True, check_like=False, check_freq=True, check_flags=True, rtol=<no_default>, atol=<no_default>, obj='DataFrame')[source]#
🌐
GitHub
github.com › numpy › numpy › issues › 17846
np.isclose() raises an exception when used with pandas 1.0 Int64Dtype objects · Issue #17846 · numpy/numpy
August 31, 2020 - import pandas as pd # v1.0.5 import numpy as np # v1.19.4 df = pd.DataFrame({"a":[1,2,3],"b":[4,5,6]}) np.isclose(df.a,df.b) # output: array([False, False, False]) df.a = df.a.astype(pd.Int64Dtype()) df.b = df.b.astype(pd.Int64Dtype()) np.isclose(df.a,df.b)
Author   samredai
🌐
GeeksforGeeks
geeksforgeeks.org › numpy-ma-allclose-function-python
numpy.ma.allclose() function - Python - GeeksforGeeks
May 5, 2020 - This function is equivalent to allclose except that masked values are treated as equal (default) or unequal, depending on the masked_equal argument.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.allclose.html
numpy.allclose — NumPy v2.3 Manual
The comparison of a and b uses standard broadcasting, which means that a and b need not have the same shape in order for allclose(a, b) to evaluate to True.
🌐
W3Schools
w3schools.com › python › ref_math_isclose.asp
Python math.isclose() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST
Top answer
1 of 1
7

I believe you need repeat columns values by numpy.broadcast_to before using numpy.isclose:

np.random.seed(142)

df = pd.DataFrame({'column':np.random.rand(10)})
print (df)
     column
0  0.902062
1  0.557808
2  0.655985
3  0.832471
4  0.199884
5  0.127254
6  0.771439
7  0.432289
8  0.385282
9  0.783643

A = [0.432, 0.783, 0.902]

#repeat by length of number of list A
len_A = len(A)
a = np.broadcast_to(df['column'].values[:, None], (len(df),len_A))
print (a)
[[0.90206152 0.90206152 0.90206152]
 [0.55780754 0.55780754 0.55780754]
 [0.65598471 0.65598471 0.65598471]
 [0.83247141 0.83247141 0.83247141]
 [0.19988419 0.19988419 0.19988419]
 [0.12725426 0.12725426 0.12725426]
 [0.77143911 0.77143911 0.77143911]
 [0.43228855 0.43228855 0.43228855]
 [0.38528223 0.38528223 0.38528223]
 [0.78364337 0.78364337 0.78364337]]

#pandas solution
m = pd.concat([df['column']] * len_A, axis=1)
print (m)
     column    column    column
0  0.902062  0.902062  0.902062
1  0.557808  0.557808  0.557808
2  0.655985  0.655985  0.655985
3  0.832471  0.832471  0.832471
4  0.199884  0.199884  0.199884
5  0.127254  0.127254  0.127254
6  0.771439  0.771439  0.771439
7  0.432289  0.432289  0.432289
8  0.385282  0.385282  0.385282
9  0.783643  0.783643  0.783643

m = np.isclose(a, b=A, atol=0.004)
print (m)
[[False False  True]
 [False False False]
 [False False False]
 [False False False]
 [False False False]
 [False False False]
 [False False False]
 [ True False False]
 [False False False]
 [False  True False]]

Last get all values with True per rows by any:

print (m.any(axis=1))
[ True False False False False False False  True False  True]

And last filter by boolean indexing:

print (df[m.any(axis=1)])
     column
0  0.902062
7  0.432289
9  0.783643
🌐
CmdLineTips
cmdlinetips.com › home › numpy allclose() function with examples
Numpy allclose() function with examples - Python and R Tips
January 4, 2023 - However, Numpy’s allclose() returns a single boolean/logical value using element-wise comparison. ... Altair Basic NumPy Book Review Data Science Data Science Books Data Science Resources Data Science Roundup Data Visualization Dimensionality Reduction Dropbox Dropbox Free Space Dropbox Tips Emacs Emacs Tips ggplot2 Linux Commands Linux Tips Mac Os X Tips Maximum Likelihood Estimation in R MLE in R NumPy Pandas Pandas 101 Pandas Dataframe Pandas Data Frame pandas groupby() Pandas select columns Pandas select_dtypes Python Python 3 Python Boxplot Python Tips R rstats R Tips Seaborn Seaborn Boxplot Seaborn Catplot Shell Scripting Sparse Matrix in Python tidy evaluation tidyverse tidyverse 101 Vim Vim Tips