diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 600171648d110..ccce1fadc16cf 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -1456,6 +1456,19 @@ def equals(self, other: object) -> bool: 0 10.0 20.0 >>> df.equals(different_data_type) False + + DataFrames with NaN in the same locations compare equal. + + >>> df_nan1 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]}) + >>> df_nan2 = pd.DataFrame({"a": [1, np.nan], "b": [3, np.nan]}) + >>> df_nan1.equals(df_nan2) + True + + If the NaN values are not in the same locations, they compare unequal. + + >>> df_nan3 = pd.DataFrame({"a": [1, np.nan], "b": [3, 4]}) + >>> df_nan1.equals(df_nan3) + False """ if not (isinstance(other, type(self)) or isinstance(self, type(other))): return False