You can use assert_frame_equal and not check the dtype of the columns.

# Pre v. 0.20.3
# from pandas.util.testing import assert_frame_equal

from pandas.testing import assert_frame_equal

assert_frame_equal(df1, df2, check_dtype=False)
Answer from Alexander on Stack Overflow
🌐
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 ·
🌐
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"
🌐
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.
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
🌐
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 [14]: a = np.asanyarray(A) ...: b = np.asanyarray(B) ...: np.allclose(a, b) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-14-9c8d10e21030> in <module> 1 a = np.asanyarray(A) 2 b = np.asanyarray(B) ----> 3 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_nan) 2187 2188 """ -> 2189 res = all(isclose(a, b, rtol=rtol, atol=atol, equal_nan=equal_nan)) 2190 return bool
🌐
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
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › numpy-allclose-in-python
numpy.allclose() in Python - GeeksforGeeks
December 28, 2018 - Python is a great language for ... and analyzing data much easier. Pandas Index.all() function checks if all the elements in the index are true or not....
🌐
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.
🌐
GitHub
github.com › numpy › numpy › issues › 17846
np.isclose() raises an exception when used with pandas 1.0 Int64Dtype objects · Issue #17846 · numpy/numpy
September 2, 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
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.allclose.html
numpy.allclose — NumPy v2.4 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.
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.allclose.html
numpy.allclose — NumPy v2.1 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.
Top answer
1 of 1
2

The columns 'b' in the example contains mixed types; strings and ints. You can't compare strings with allclose as strings are either different or not. You should, if possible, have your data organised so that columns are of a single type. If you had, you could use np.allclose to compare the numeric columns and the standard == operator to compare the columns containing strings. In the example, columns 'a' are numeric so np.allclose works:

In [25]: np.allclose(old.a, new.a)
Out[25]: False

However, it returned False because equating null values always returns False, which is another subtlety you need to be be aware of when comparing DataFrames. In this case you could do

In [25]: np.allclose(old.fillna(value=0).a, new.fillna(value=0).a)
Out[25]: True

In the small example you give, the transpose of the DataFrame has columns of a single type so maybe you should be working with that. Note, however, that simply taking the transpose won't change the data types.

In [18]: old.T.dtypes

Out[18]:
x    object
y    object
z    object

but using the convert_objects method will

In [20]: old.T.convert_objects().dtypes
Out[20]:
x    float64
y     object
z    float64
dtype: object

In general, you can check the dtypes of each columns by calling DataFrame.dtypes. You can pick out string (object) columns with something like

obj_cols = df.columns[df.dtypes == object]
num_cols = df.columns[df.dtypes != object]   #this would also include any time columns

Then do

np.allclose(df1[num_cols].fillna(0), df2[num_cols].fillna(0))

and

(df1[obj_cols].fillna('') == df2[obj_cols].fillna('')).all().all()

EDIT: In a more general setting you might want to be a bit more careful when handling nans. You could do the above, but also make sure that the null entries match exactly, since replacing nans with 0 might give an unwanted equality (you might have a 0 in one DataFrame and nan in another and you would still get equality, likewise for strings). You can do this as follow:

(old.isnull() == new.isnull()).all().all()
🌐
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 ·
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-math-library-isclose-method
Python math library | isclose() method - GeeksforGeeks
July 11, 2025 - Pandas · Practice · Django · Flask · Last Updated : 11 Jul, 2025 · In the Python math module, math.isclose() the method is used to determine whether two floating point numbers are close in value. To use this function in Python you must import the math module.
🌐
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