polars.Series.cast

Series.cast(dtype: Union[Type[polars.datatypes.DataType], Type[int], Type[float], Type[str], Type[bool], polars.datatypes.DataType], strict: bool = True) polars.internals.series.Series

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
]