-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Update the pandas.DataFrame.abs docstring #20194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
99332e4
7da5bb6
4165872
54fffbe
150f849
34296b2
5e83e23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7115,12 +7115,61 @@ def _tz_localize(ax, tz, ambiguous): | |
# Numeric Methods | ||
def abs(self): | ||
""" | ||
Return an object with absolute value taken--only applicable to objects | ||
that are all numeric. | ||
Return a Series/DataFrame with absolute numeric value of each object. | ||
|
||
This function only applies to objects that are all numeric. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. objects -> elements |
||
|
||
Returns | ||
------- | ||
abs: type of caller | ||
abs | ||
Series/DataFrame containing the absolute value of each object. | ||
|
||
Notes | ||
----- | ||
For ``complex`` inputs, ``1.2 + 1j``, the absolute value is | ||
:math:`\\sqrt{ a^2 + b^2 }`. See the Python | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like something missing from the end here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I was going to referer to the Python documentation on |
||
|
||
Examples | ||
-------- | ||
Absolute numeric values in a ``Series``. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for the quotes on Series There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
|
||
>>> s = pd.Series([-1.10, 2, -3.33, 4]) | ||
>>> s.abs() | ||
0 1.10 | ||
1 2.00 | ||
2 3.33 | ||
3 4.00 | ||
dtype: float64 | ||
|
||
Absolute numeric values in a ``Series`` with ``complex`` numbers. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could add an example for a Series of timedelta64 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a |
||
|
||
>>> s = pd.Series([1.2 + 1j]) | ||
>>> s.abs() | ||
0 1.56205 | ||
dtype: float64 | ||
|
||
Select rows with data closest to certian value using argsort (from | ||
`StackOverflow | ||
<http://stackoverflow.com/questions/17758023/return-rows-in-a-dataframe-closest-to-a-user-defined-number>`__). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably too long of a line. SO should have a "share" URL that is shorter. |
||
|
||
>>> df = pd.DataFrame({ | ||
... 'a': [4, 5, 6, 7], | ||
... 'b': [10, 20, 30, 40], | ||
... 'c': [100, 50, -30, -50] | ||
... }) | ||
>>> df | ||
a b c | ||
0 4 10 100 | ||
1 5 20 50 | ||
2 6 30 -30 | ||
3 7 40 -50 | ||
>>> a_value = 43.0 | ||
>>> df.loc[(df.c - a_value).abs().argsort()] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason to assign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example fails if |
||
a b c | ||
1 5 20 50 | ||
0 4 10 100 | ||
2 6 30 -30 | ||
3 7 40 -50 | ||
""" | ||
return np.abs(self) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you repalce "object" with "element"? That's our usual noun for items in a frame.