polars.Series.cast#

Series.cast(dtype: type[polars.datatypes.DataType] | type[int] | type[float] | type[str] | type[bool] | polars.datatypes.DataType, strict: bool = True) Series[source]#

Cast between data types.

Parameters:
dtype

DataType to cast to

strict

Throw an error if a cast could not be done for instance due to an overflow

Examples

>>> s = pl.Series("a", [True, False, True])
>>> s
shape: (3,)
Series: 'a' [bool]
[
    true
    false
    true
]
>>> s.cast(pl.UInt32)
shape: (3,)
Series: 'a' [u32]
[
    1
    0
    1
]