polars.Series.str.to_decimal#
- Series.str.to_decimal( ) Series[source]#
Convert a String column into a Decimal column.
This method infers the needed parameters
precisionandscaleif not given.Changed in version 1.20.0: Parameter
inference_lengthshould now be passed as a keyword argument.- Parameters:
- inference_length
Number of elements to parse to determine the
precisionandscale- scale
Number of digits after the comma to use for the decimals.
Examples
>>> s = pl.Series( ... ["40.12", "3420.13", "120134.19", "3212.98", "12.90", "143.09", "143.9"] ... ) >>> s.str.to_decimal() shape: (7,) Series: '' [decimal[8,2]] [ 40.12 3420.13 120134.19 3212.98 12.90 143.09 143.90 ]