Truncate a Series or DataFrame before and after some index value. This is a useful shorthand for boolean indexing based on index values above or below certain thresholds. Parameters ---------- before : date, str, int Truncate all rows be
(
self,
before=None,
after=None,
axis: Axis | None = None,
copy: bool | lib.NoDefault = lib.no_default,
)
| 10672 | |
| 10673 | @final |
| 10674 | def truncate( |
| 10675 | self, |
| 10676 | before=None, |
| 10677 | after=None, |
| 10678 | axis: Axis | None = None, |
| 10679 | copy: bool | lib.NoDefault = lib.no_default, |
| 10680 | ) -> Self: |
| 10681 | """ |
| 10682 | Truncate a Series or DataFrame before and after some index value. |
| 10683 | |
| 10684 | This is a useful shorthand for boolean indexing based on index |
| 10685 | values above or below certain thresholds. |
| 10686 | |
| 10687 | Parameters |
| 10688 | ---------- |
| 10689 | before : date, str, int |
| 10690 | Truncate all rows before this index value. |
| 10691 | after : date, str, int |
| 10692 | Truncate all rows after this index value. |
| 10693 | axis : {0 or 'index', 1 or 'columns'}, optional |
| 10694 | Axis to truncate. Truncates the index (rows) by default. |
| 10695 | For `Series` this parameter is unused and defaults to 0. |
| 10696 | copy : bool, default False |
| 10697 | This keyword is now ignored; changing its value will have no |
| 10698 | impact on the method. |
| 10699 | |
| 10700 | .. deprecated:: 3.0.0 |
| 10701 | |
| 10702 | This keyword is ignored and will be removed in pandas 4.0. Since |
| 10703 | pandas 3.0, this method always returns a new object using a lazy |
| 10704 | copy mechanism that defers copies until necessary |
| 10705 | (Copy-on-Write). See the `user guide on Copy-on-Write |
| 10706 | <https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__ |
| 10707 | for more details. |
| 10708 | |
| 10709 | Returns |
| 10710 | ------- |
| 10711 | type of caller |
| 10712 | The truncated Series or DataFrame. |
| 10713 | |
| 10714 | See Also |
| 10715 | -------- |
| 10716 | DataFrame.loc : Select a subset of a DataFrame by label. |
| 10717 | DataFrame.iloc : Select a subset of a DataFrame by position. |
| 10718 | |
| 10719 | Notes |
| 10720 | ----- |
| 10721 | If the index being truncated contains only datetime values, |
| 10722 | `before` and `after` may be specified as strings instead of |
| 10723 | Timestamps. |
| 10724 | |
| 10725 | Examples |
| 10726 | -------- |
| 10727 | >>> df = pd.DataFrame( |
| 10728 | ... { |
| 10729 | ... "A": ["a", "b", "c", "d", "e"], |
| 10730 | ... "B": ["f", "g", "h", "i", "j"], |
| 10731 | ... "C": ["k", "l", "m", "n", "o"], |