-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Improve truncate docstring (#17763) #17925
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
|
@@ -6330,17 +6330,64 @@ def truncate(self, before=None, after=None, axis=None, copy=True): | |
|
||
Parameters | ||
---------- | ||
before : date | ||
Truncate before index value | ||
after : date | ||
Truncate after index value | ||
axis : the truncation axis, defaults to the stat axis | ||
before : date, string, int | ||
Truncate all rows before this index value | ||
after : date, string, int | ||
Truncate all rows after this index value | ||
axis : {0 or 'index', 1 or 'columns'} | ||
* 0 or 'index': apply truncation to rows | ||
* 1 or 'columns': apply truncation to columns | ||
Default is stat axis for given data type (0 for Series and | ||
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. blank line above this one |
||
DataFrames, 1 for Panels) | ||
copy : boolean, default is True, | ||
return a copy of the truncated section | ||
|
||
Returns | ||
------- | ||
truncated : type of caller | ||
|
||
Examples | ||
-------- | ||
>>> df = pd.DataFrame({'A': ['a', 'b', 'c', 'd', 'e'], | ||
... 'B': ['f', 'g', 'h', 'i', 'j'], | ||
... 'C': ['k', 'l', 'm', 'n', 'o']}, | ||
... index=[1, 2, 3, 4, 5]) | ||
>>> df.truncate(before=2, after=4) | ||
A B C | ||
2 b g l | ||
3 c h m | ||
4 d i n | ||
>>> df = pd.DataFrame({'A': [1, 2, 3, 4, 5], | ||
... 'B': [6, 7, 8, 9, 10], | ||
... 'C': [11, 12, 13, 14, 15]}, | ||
... index=['a', 'b', 'c', 'd', 'e']) | ||
>>> df.truncate(before='b', after='d') | ||
A B C | ||
b 2 7 12 | ||
c 3 8 13 | ||
d 4 9 14 | ||
|
||
The index values in ``truncate`` can be datetimes or string | ||
dates. Note that ``truncate`` assumes a 0 value for any unspecified | ||
date component in a ``DatetimeIndex`` in contrast to slicing which | ||
returns any partially matching dates. | ||
|
||
>>> dates = pd.date_range('2016-1-1', '2016-2-1', freq='s') | ||
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. nitpick: I prefer to use iso dates in our docs (apart for examples specifically on date string parsing), so "2016-01-01" etc |
||
>>> df = pd.DataFrame(index=dates, data={'A': 1}) | ||
>>> df.truncate('2016-1-5', '2016-1-10').tail() | ||
A | ||
2016-01-09 23:59:56 1 | ||
2016-01-09 23:59:57 1 | ||
2016-01-09 23:59:58 1 | ||
2016-01-09 23:59:59 1 | ||
2016-01-10 00:00:00 1 | ||
>>> df.loc['2016-1-5':'2016-1-10', :].tail() | ||
A | ||
2016-01-10 23:59:55 1 | ||
2016-01-10 23:59:56 1 | ||
2016-01-10 23:59:57 1 | ||
2016-01-10 23:59:58 1 | ||
2016-01-10 23:59:59 1 | ||
""" | ||
|
||
if axis is None: | ||
|
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.
maybe add the equivalent slicing example as well to show it is not the same ?