polars.Series.str.parse_int#

Series.str.parse_int(radix: int = 2, *, strict: bool = True) Series[source]#

Parse integers with base radix from strings.

By default base 2. ParseError/Overflows become Nulls.

Parameters:
radix

Positive integer which is the base of the string we are parsing. Default: 2

strict

Bool, Default=True will raise any ParseError or overflow as ComputeError. False silently convert to Null.

Returns:
Series

Series of data type Int32.

Examples

>>> s = pl.Series("bin", ["110", "101", "010", "invalid"])
>>> s.str.parse_int(2, strict=False)
shape: (4,)
Series: 'bin' [i32]
[
        6
        5
        2
        null
]
>>> s = pl.Series("hex", ["fa1e", "ff00", "cafe", None])
>>> s.str.parse_int(16)
shape: (4,)
Series: 'hex' [i32]
[
        64030
        65280
        51966
        null
]