polars.Series.truncate#

Series.truncate(decimals: int = 0) Series[source]#

Truncate numeric data toward zero to decimals number of decimal places.

Parameters:
decimals

Number of decimal places to truncate to.

See also

round

Round to a given number of decimals.

floor

Round down to the nearest integer.

ceil

Round up to the nearest integer.

Notes

  • Truncation discards the fractional part beyond the given number of decimals. For example, when rounding to 0 decimals 0.25, -0.25, 0.99, and -0.99 will all round to 0. When rounding to 1 decimal 1.9999 rounds to 1.9 and -1.9999 rounds to -1.9. There is no tiebreak behaviour at midpoint values as there is with round() so 0.5 and -0.5 will also round to 0 when decimals=1.

  • This method performs numeric truncation. For truncating temporal data (dates/datetimes), use Series.dt.truncate() instead.

Examples

>>> s = pl.Series("a", [1.12345, 2.56789, 3.991234])
>>> s.truncate(2)
shape: (3,)
Series: 'a' [f64]
[
        1.12
        2.56
        3.99
]
>>> s = pl.Series("a", [-1.78, 2.56, -3.99])
>>> s.truncate(0)
shape: (3,)
Series: 'a' [f64]
[
        -1.0
        2.0
        -3.0
]