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. The row/column index do not
(self, other: object)
| 1355 | |
| 1356 | @final |
| 1357 | def equals(self, other: object) -> bool: |
| 1358 | """ |
| 1359 | Test whether two objects contain the same elements. |
| 1360 | |
| 1361 | This function allows two Series or DataFrames to be compared against |
| 1362 | each other to see if they have the same shape and elements. NaNs in |
| 1363 | the same location are considered equal. |
| 1364 | |
| 1365 | The row/column index do not need to have the same type, as long |
| 1366 | as the values are considered equal. Corresponding columns and |
| 1367 | index must be of the same dtype. |
| 1368 | |
| 1369 | Parameters |
| 1370 | ---------- |
| 1371 | other : Series or DataFrame |
| 1372 | The other Series or DataFrame to be compared with the first. |
| 1373 | |
| 1374 | Returns |
| 1375 | ------- |
| 1376 | bool |
| 1377 | True if all elements are the same in both objects, False |
| 1378 | otherwise. |
| 1379 | |
| 1380 | See Also |
| 1381 | -------- |
| 1382 | Series.eq : Compare two Series objects of the same length |
| 1383 | and return a Series where each element is True if the element |
| 1384 | in each Series is equal, False otherwise. |
| 1385 | DataFrame.eq : Compare two DataFrame objects of the same shape and |
| 1386 | return a DataFrame where each element is True if the respective |
| 1387 | element in each DataFrame is equal, False otherwise. |
| 1388 | testing.assert_series_equal : Raises an AssertionError if left and |
| 1389 | right are not equal. Provides an easy interface to ignore |
| 1390 | inequality in dtypes, indexes and precision among others. |
| 1391 | testing.assert_frame_equal : Like assert_series_equal, but targets |
| 1392 | DataFrames. |
| 1393 | numpy.array_equal : Return True if two arrays have the same shape |
| 1394 | and elements, False otherwise. |
| 1395 | |
| 1396 | Examples |
| 1397 | -------- |
| 1398 | >>> df = pd.DataFrame({1: [10], 2: [20]}) |
| 1399 | >>> df |
| 1400 | 1 2 |
| 1401 | 0 10 20 |
| 1402 | |
| 1403 | DataFrames df and exactly_equal have the same types and values for |
| 1404 | their elements and column labels, which will return True. |
| 1405 | |
| 1406 | >>> exactly_equal = pd.DataFrame({1: [10], 2: [20]}) |
| 1407 | >>> exactly_equal |
| 1408 | 1 2 |
| 1409 | 0 10 20 |
| 1410 | >>> df.equals(exactly_equal) |
| 1411 | True |
| 1412 | |
| 1413 | DataFrames df and different_column_type have the same element |
| 1414 | types and values, but have different types for the column labels, |
no outgoing calls