-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the pandas.Series.shift docstring #20472
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8854ee3
Original PR changes to shift docstring
datapythonista 0e0970d
Minor fixes and removing some examples
datapythonista f6afea0
Addressing comments from code review, and removing notes, as it's dup…
datapythonista 4d9c3c0
Fixing non-ascii quote
datapythonista File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8361,22 +8361,24 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, | |
errors=errors) | ||
|
||
_shared_docs['shift'] = (""" | ||
Shift index by desired number of periods with an optional time freq | ||
Shift index by desired number of periods with an optional time `freq`. | ||
|
||
When `freq` is not passed, shift the index without realigning the data. | ||
If `freq` is passed (in this case, the index must be date or datetime, | ||
or it will raise a `NotImplementedError`), the index will be | ||
increased using the periods and the `freq`. | ||
|
||
Parameters | ||
---------- | ||
periods : int | ||
Number of periods to move, can be positive or negative. | ||
freq : DateOffset, timedelta, or time rule string, optional | ||
Increment to use from the tseries module or time rule (e.g. 'EOM'). | ||
See Notes. | ||
axis : %(axes_single_arg)s | ||
|
||
See Also | ||
-------- | ||
Index.shift : Shift values of Index. | ||
DatetimeIndex.shift : Shift values of DatetimeIndex. | ||
PeriodIndex.shift : Shift values of PeriodIndex. | ||
Number of periods to shift. Can be positive or negative. | ||
freq : DateOffset, timedelta, or str, optional | ||
Offset to use from the tseries module or time rule (e.g. 'EOM'). | ||
If `freq` is specified then the index values are shifted but the | ||
data is not realigned. That is, use `freq` if you would like to | ||
extend the index when shifting and preserve the original data. | ||
axis : {0 or ‘index’, 1 or ‘columns’, None}, default None | ||
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. don't we usually avoid fancy quotes? |
||
Shift direction. | ||
|
||
Notes | ||
----- | ||
|
@@ -8386,7 +8388,38 @@ def mask(self, cond, other=np.nan, inplace=False, axis=None, level=None, | |
|
||
Returns | ||
------- | ||
shifted : %(klass)s | ||
%(klass)s | ||
Copy of input object, shifted. | ||
|
||
See Also | ||
-------- | ||
Index.shift : Shift values of Index. | ||
DatetimeIndex.shift : Shift values of DatetimeIndex. | ||
PeriodIndex.shift : Shift values of PeriodIndex. | ||
tshift : Shift the time index, using the index’s frequency if | ||
available. | ||
|
||
Examples | ||
-------- | ||
>>> df = pd.DataFrame({'Col1': [10, 20, 15, 30, 45], | ||
... 'Col2': [13, 23, 18, 33, 48], | ||
... 'Col3': [17, 27, 22, 37, 52]}) | ||
|
||
>>> df.shift(periods=3) | ||
Col1 Col2 Col3 | ||
0 NaN NaN NaN | ||
1 NaN NaN NaN | ||
2 NaN NaN NaN | ||
3 10.0 13.0 17.0 | ||
4 20.0 23.0 27.0 | ||
|
||
>>> df.shift(periods=1, axis='columns') | ||
Col1 Col2 Col3 | ||
0 NaN 10.0 13.0 | ||
1 NaN 20.0 23.0 | ||
2 NaN 15.0 18.0 | ||
3 NaN 30.0 33.0 | ||
4 NaN 45.0 48.0 | ||
""") | ||
|
||
@Appender(_shared_docs['shift'] % _shared_doc_kwargs) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
worth specifying tseries.offsets?