def truncate(self, before: Optional[Any]=None, after: Optional[Any]=None, axis: Optional[Axis]=None, copy: bool_type=True) -> DataFrameOrSeries:
    '\n        Truncate a Series or DataFrame before and after some index value.\n\n        This is a useful shorthand for boolean indexing based on index\n        values above or below certain thresholds.\n\n        .. note:: This API is dependent on :meth:`Index.is_monotonic_increasing`\n            which can be expensive.\n\n        Parameters\n        ----------\n        before : date, str, int\n            Truncate all rows before this index value.\n        after : date, str, int\n            Truncate all rows after this index value.\n        axis : {0 or \'index\', 1 or \'columns\'}, optional\n            Axis to truncate. Truncates the index (rows) by default.\n        copy : bool, default is True,\n            Return a copy of the truncated section.\n\n        Returns\n        -------\n        type of caller\n            The truncated Series or DataFrame.\n\n        See Also\n        --------\n        DataFrame.loc : Select a subset of a DataFrame by label.\n        DataFrame.iloc : Select a subset of a DataFrame by position.\n\n        Examples\n        --------\n        >>> df = ps.DataFrame({\'A\': [\'a\', \'b\', \'c\', \'d\', \'e\'],\n        ...                    \'B\': [\'f\', \'g\', \'h\', \'i\', \'j\'],\n        ...                    \'C\': [\'k\', \'l\', \'m\', \'n\', \'o\']},\n        ...                   index=[1, 2, 3, 4, 5])\n        >>> df\n           A  B  C\n        1  a  f  k\n        2  b  g  l\n        3  c  h  m\n        4  d  i  n\n        5  e  j  o\n\n        >>> df.truncate(before=2, after=4)\n           A  B  C\n        2  b  g  l\n        3  c  h  m\n        4  d  i  n\n\n        The columns of a DataFrame can be truncated.\n\n        >>> df.truncate(before="A", after="B", axis="columns")\n           A  B\n        1  a  f\n        2  b  g\n        3  c  h\n        4  d  i\n        5  e  j\n\n        For Series, only rows can be truncated.\n\n        >>> df[\'A\'].truncate(before=2, after=4)\n        2    b\n        3    c\n        4    d\n        Name: A, dtype: object\n\n        A Series has index that sorted integers.\n\n        >>> s = ps.Series([10, 20, 30, 40, 50, 60, 70],\n        ...               index=[1, 2, 3, 4, 5, 6, 7])\n        >>> s\n        1    10\n        2    20\n        3    30\n        4    40\n        5    50\n        6    60\n        7    70\n        dtype: int64\n\n        >>> s.truncate(2, 5)\n        2    20\n        3    30\n        4    40\n        5    50\n        dtype: int64\n\n        A Series has index that sorted strings.\n\n        >>> s = ps.Series([10, 20, 30, 40, 50, 60, 70],\n        ...               index=[\'a\', \'b\', \'c\', \'d\', \'e\', \'f\', \'g\'])\n        >>> s\n        a    10\n        b    20\n        c    30\n        d    40\n        e    50\n        f    60\n        g    70\n        dtype: int64\n\n        >>> s.truncate(\'b\', \'e\')\n        b    20\n        c    30\n        d    40\n        e    50\n        dtype: int64\n        '
    from pyspark.pandas.series import first_series
    axis = validate_axis(axis)
    indexes = self.index
    indexes_increasing = indexes.is_monotonic_increasing
    if ((not indexes_increasing) and (not indexes.is_monotonic_decreasing)):
        raise ValueError('truncate requires a sorted index')
    if ((before is None) and (after is None)):
        return cast(Union[(ps.DataFrame, ps.Series)], (self.copy() if copy else self))
    if (((before is not None) and (after is not None)) and (before > after)):
        raise ValueError(('Truncate: %s must be after %s' % (after, before)))
    if isinstance(self, ps.Series):
        if indexes_increasing:
            result = first_series(self.to_frame().loc[before:after]).rename(self.name)
        else:
            result = first_series(self.to_frame().loc[after:before]).rename(self.name)
    elif isinstance(self, ps.DataFrame):
        if (axis == 0):
            if indexes_increasing:
                result = self.loc[before:after]
            else:
                result = self.loc[after:before]
        elif (axis == 1):
            result = self.loc[:, before:after]
    return cast(DataFrameOrSeries, (result.copy() if copy else result))
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.

.. note:: This API is dependent on :meth:`Index.is_monotonic_increasing`
    which can be expensive.

Parameters
----------
before : date, str, int
    Truncate all rows before this index value.
after : date, str, int
    Truncate all rows after this index value.
axis : {0 or 'index', 1 or 'columns'}, optional
    Axis to truncate. Truncates the index (rows) by default.
copy : bool, default is True,
    Return a copy of the truncated section.

Returns
-------
type of caller
    The truncated Series or DataFrame.

See Also
--------
DataFrame.loc : Select a subset of a DataFrame by label.
DataFrame.iloc : Select a subset of a DataFrame by position.

Examples
--------
>>> df = ps.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
   A  B  C
1  a  f  k
2  b  g  l
3  c  h  m
4  d  i  n
5  e  j  o

>>> df.truncate(before=2, after=4)
   A  B  C
2  b  g  l
3  c  h  m
4  d  i  n

The columns of a DataFrame can be truncated.

>>> df.truncate(before="A", after="B", axis="columns")
   A  B
1  a  f
2  b  g
3  c  h
4  d  i
5  e  j

For Series, only rows can be truncated.

>>> df['A'].truncate(before=2, after=4)
2    b
3    c
4    d
Name: A, dtype: object

A Series has index that sorted integers.

>>> s = ps.Series([10, 20, 30, 40, 50, 60, 70],
...               index=[1, 2, 3, 4, 5, 6, 7])
>>> s
1    10
2    20
3    30
4    40
5    50
6    60
7    70
dtype: int64

>>> s.truncate(2, 5)
2    20
3    30
4    40
5    50
dtype: int64

A Series has index that sorted strings.

>>> s = ps.Series([10, 20, 30, 40, 50, 60, 70],
...               index=['a', 'b', 'c', 'd', 'e', 'f', 'g'])
>>> s
a    10
b    20
c    30
d    40
e    50
f    60
g    70
dtype: int64

>>> s.truncate('b', 'e')
b    20
c    30
d    40
e    50
dtype: int64
def truncate(self, before: Optional[Any]=None, after: Optional[Any]=None, axis: Optional[Axis]=None, copy: bool_type=True) -> DataFrameOrSeries:
    '\n        Truncate a Series or DataFrame before and after some index value.\n\n        This is a useful shorthand for boolean indexing based on index\n        values above or below certain thresholds.\n\n        .. note:: This API is dependent on :meth:`Index.is_monotonic_increasing`\n            which can be expensive.\n\n        Parameters\n        ----------\n        before : date, str, int\n            Truncate all rows before this index value.\n        after : date, str, int\n            Truncate all rows after this index value.\n        axis : {0 or \'index\', 1 or \'columns\'}, optional\n            Axis to truncate. Truncates the index (rows) by default.\n        copy : bool, default is True,\n            Return a copy of the truncated section.\n\n        Returns\n        -------\n        type of caller\n            The truncated Series or DataFrame.\n\n        See Also\n        --------\n        DataFrame.loc : Select a subset of a DataFrame by label.\n        DataFrame.iloc : Select a subset of a DataFrame by position.\n\n        Examples\n        --------\n        >>> df = ps.DataFrame({\'A\': [\'a\', \'b\', \'c\', \'d\', \'e\'],\n        ...                    \'B\': [\'f\', \'g\', \'h\', \'i\', \'j\'],\n        ...                    \'C\': [\'k\', \'l\', \'m\', \'n\', \'o\']},\n        ...                   index=[1, 2, 3, 4, 5])\n        >>> df\n           A  B  C\n        1  a  f  k\n        2  b  g  l\n        3  c  h  m\n        4  d  i  n\n        5  e  j  o\n\n        >>> df.truncate(before=2, after=4)\n           A  B  C\n        2  b  g  l\n        3  c  h  m\n        4  d  i  n\n\n        The columns of a DataFrame can be truncated.\n\n        >>> df.truncate(before="A", after="B", axis="columns")\n           A  B\n        1  a  f\n        2  b  g\n        3  c  h\n        4  d  i\n        5  e  j\n\n        For Series, only rows can be truncated.\n\n        >>> df[\'A\'].truncate(before=2, after=4)\n        2    b\n        3    c\n        4    d\n        Name: A, dtype: object\n\n        A Series has index that sorted integers.\n\n        >>> s = ps.Series([10, 20, 30, 40, 50, 60, 70],\n        ...               index=[1, 2, 3, 4, 5, 6, 7])\n        >>> s\n        1    10\n        2    20\n        3    30\n        4    40\n        5    50\n        6    60\n        7    70\n        dtype: int64\n\n        >>> s.truncate(2, 5)\n        2    20\n        3    30\n        4    40\n        5    50\n        dtype: int64\n\n        A Series has index that sorted strings.\n\n        >>> s = ps.Series([10, 20, 30, 40, 50, 60, 70],\n        ...               index=[\'a\', \'b\', \'c\', \'d\', \'e\', \'f\', \'g\'])\n        >>> s\n        a    10\n        b    20\n        c    30\n        d    40\n        e    50\n        f    60\n        g    70\n        dtype: int64\n\n        >>> s.truncate(\'b\', \'e\')\n        b    20\n        c    30\n        d    40\n        e    50\n        dtype: int64\n        '
    from pyspark.pandas.series import first_series
    axis = validate_axis(axis)
    indexes = self.index
    indexes_increasing = indexes.is_monotonic_increasing
    if ((not indexes_increasing) and (not indexes.is_monotonic_decreasing)):
        raise ValueError('truncate requires a sorted index')
    if ((before is None) and (after is None)):
        return cast(Union[(ps.DataFrame, ps.Series)], (self.copy() if copy else self))
    if (((before is not None) and (after is not None)) and (before > after)):
        raise ValueError(('Truncate: %s must be after %s' % (after, before)))
    if isinstance(self, ps.Series):
        if indexes_increasing:
            result = first_series(self.to_frame().loc[before:after]).rename(self.name)
        else:
            result = first_series(self.to_frame().loc[after:before]).rename(self.name)
    elif isinstance(self, ps.DataFrame):
        if (axis == 0):
            if indexes_increasing:
                result = self.loc[before:after]
            else:
                result = self.loc[after:before]
        elif (axis == 1):
            result = self.loc[:, before:after]
    return cast(DataFrameOrSeries, (result.copy() if copy else result))