w3resource

Pandas Series: truncate() function

Series-truncate() function

The truncate() function is used to 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.

Syntax:

Series.truncate(self, before=None, after=None, axis=None, copy=True)
Pandas Series truncate image
Name Description Type/Default Value Required / Optional
before Truncate all rows before this index value. date, string, int Required
after WTruncate all rows after this index value. date, string, int Required
axis Axis to truncate. Truncates the index (rows) by default. {0 or ‘index’, 1 or ‘columns’} optional
copy Return a copy of the truncated section. boolean
Default Value: True
optional

Returns: type of caller
The truncated Series or DataFrame.

Notes: If the index being truncated contains only datetime values, before and after may be specified as strings instead of Timestamps.

Example:


Download the above Notebook from here.



Inviting useful, relevant, well-written and unique guest posts