MCPcopy
hub / github.com/pandas-dev/pandas / abs

Method abs

pandas/core/generic.py:1507–1575  ·  view source on GitHub ↗

Return a Series/DataFrame with absolute numeric value of each element. This function only applies to elements that are all numeric. Returns ------- abs Series/DataFrame containing the absolute value of each element. See Also ---

(self)

Source from the content-addressed store, hash-verified

1505
1506 @final
1507 def abs(self) -> Self:
1508 """
1509 Return a Series/DataFrame with absolute numeric value of each element.
1510
1511 This function only applies to elements that are all numeric.
1512
1513 Returns
1514 -------
1515 abs
1516 Series/DataFrame containing the absolute value of each element.
1517
1518 See Also
1519 --------
1520 numpy.absolute : Calculate the absolute value element-wise.
1521
1522 Notes
1523 -----
1524 For ``complex`` inputs, ``1.2 + 1j``, the absolute value is
1525 :math:`\\sqrt{ a^2 + b^2 }`.
1526
1527 Examples
1528 --------
1529 Absolute numeric values in a Series.
1530
1531 >>> s = pd.Series([-1.10, 2, -3.33, 4])
1532 >>> s.abs()
1533 0 1.10
1534 1 2.00
1535 2 3.33
1536 3 4.00
1537 dtype: float64
1538
1539 Absolute numeric values in a Series with complex numbers.
1540
1541 >>> s = pd.Series([1.2 + 1j])
1542 >>> s.abs()
1543 0 1.56205
1544 dtype: float64
1545
1546 Absolute numeric values in a Series with a Timedelta element.
1547
1548 >>> s = pd.Series([pd.Timedelta("1 days")])
1549 >>> s.abs()
1550 0 1 days
1551 dtype: timedelta64[us]
1552
1553 Select rows with data closest to certain value using argsort (from
1554 `StackOverflow <https://stackoverflow.com/a/17758115>`__).
1555
1556 >>> df = pd.DataFrame(
1557 ... {"a": [4, 5, 6, 7], "b": [10, 20, 30, 40], "c": [100, 50, -30, -50]}
1558 ... )
1559 >>> df
1560 a b c
1561 0 4 10 100
1562 1 5 20 50
1563 2 6 30 -30
1564 3 7 40 -50

Callers 15

__abs__Method · 0.95
setupMethod · 0.80
setupMethod · 0.80
nanskewFunction · 0.80
nankurtFunction · 0.80
_zero_out_fperrFunction · 0.80
__abs__Method · 0.80
get_result_as_arrayMethod · 0.80
arr_strFunction · 0.80
arr_utfFunction · 0.80
setup_methodMethod · 0.80

Calls 3

__finalize__Method · 0.80
applyMethod · 0.45
_constructor_from_mgrMethod · 0.45

Tested by 15

arr_strFunction · 0.64
arr_utfFunction · 0.64
setup_methodMethod · 0.64
testitMethod · 0.64
test_absMethod · 0.64
test_ufuncMethod · 0.64
test_corr_sanityFunction · 0.64
test_ewma_adjustFunction · 0.64