-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
DOC: update the pandas.DataFrame.pct_change docstring #20310
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 7 commits
41cb90f
f818921
972e3b1
6a4c0e6
dc2cb5a
ea99c67
a0d8ee7
4ecaf62
a0dcac2
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 |
---|---|---|
|
@@ -7515,29 +7515,91 @@ def _check_percentile(self, q): | |
return q | ||
|
||
_shared_docs['pct_change'] = """ | ||
Percent change over given number of periods. | ||
Percentage change between the current and previous element. | ||
|
||
This is useful in comparing the percentage of change in a time series | ||
of elements. | ||
|
||
Parameters | ||
---------- | ||
periods : int, default 1 | ||
Periods to shift for forming percent change | ||
Periods to shift for forming percent change. | ||
fill_method : str, default 'pad' | ||
How to handle NAs before computing percent changes | ||
How to handle NAs before computing percent changes. | ||
limit : int, default None | ||
The number of consecutive NAs to fill before stopping | ||
The number of consecutive NAs to fill before stopping. | ||
freq : DateOffset, timedelta, or offset alias string, optional | ||
Increment to use from time series API (e.g. 'M' or BDay()) | ||
Increment to use from time series API (e.g. 'M' or BDay()). | ||
**kwargs : mapping, optional | ||
Additional keyword arguments are passed into | ||
``DataFrame.shift``/``Series.shift``. | ||
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. Single backticks. "or" instead of |
||
|
||
Returns | ||
------- | ||
chg : %(klass)s | ||
chg : Series or DataFrame, same type as the calling object | ||
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.
|
||
|
||
Notes | ||
----- | ||
|
||
By default, the percentage change is calculated along the stat | ||
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. I don't think most users will understand |
||
axis: 0, or ``Index``, for ``DataFrame`` and 1, or ``minor`` for | ||
``Panel``. You can change this with the ``axis`` keyword argument. | ||
|
||
Percentage change in French franc, Deutsche Mark, and Italian lira from | ||
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. Move under the "Examples" header. |
||
1 January 1980 to 1 March 1980. | ||
|
||
>>> df = pd.DataFrame({ | ||
... 'FR': [4.0405, 4.0963, 4.3149], | ||
... 'GR': [1.7246, 1.7482, 1.8519], | ||
... 'IT': [804.74, 810.01, 860.13]}, | ||
... index=['1980-01-01', '1980-02-01', '1980-03-01']) | ||
>>> df | ||
FR GR IT | ||
1980-01-01 4.0405 1.7246 804.74 | ||
1980-02-01 4.0963 1.7482 810.01 | ||
1980-03-01 4.3149 1.8519 860.13 | ||
>>> df.pct_change() | ||
FR GR IT | ||
1980-01-01 NaN NaN NaN | ||
1980-02-01 0.013810 0.013684 0.006549 | ||
1980-03-01 0.053365 0.059318 0.061876 | ||
|
||
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. Show an example with |
||
Examples | ||
-------- | ||
See the percentage change in a Series. | ||
|
||
>>> s = pd.Series([90, 91, 85]) | ||
>>> s | ||
0 90 | ||
1 91 | ||
2 85 | ||
dtype: int64 | ||
>>> s.pct_change() | ||
0 NaN | ||
1 0.011111 | ||
2 -0.065934 | ||
dtype: float64 | ||
|
||
See the percentage change in a Series where filling NAs with last | ||
valid observation forward to next valid. | ||
|
||
>>> s = pd.Series([90, 91, None, 85]) | ||
>>> s | ||
0 90.0 | ||
1 91.0 | ||
2 NaN | ||
3 85.0 | ||
dtype: float64 | ||
>>> s.pct_change(fill_method='ffill') | ||
0 NaN | ||
1 0.011111 | ||
2 0.000000 | ||
3 -0.065934 | ||
dtype: float64 | ||
|
||
See Also | ||
-------- | ||
pandas.DataFrame.diff : see the difference of two columns | ||
pandas.Series.diff : see the difference of two columns | ||
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. Can you move this above the "Examples" section? 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. Can also remove the |
||
""" | ||
|
||
@Appender(_shared_docs['pct_change'] % _shared_doc_kwargs) | ||
|
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 remove the type here. Just
**kwargs
.