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.


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

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.


Download the Pandas Series Notebooks from here.

Previous: Series-tail() function
Next: Series-where() function

Share this Tutorial / Exercise on : Facebook and Twitter