Is there any way to specify a format specifier if, for example, casting a pl.Float32
, without resorting to complex searches for the period character? As in something like:
s = pl.Series([1.2345, 2.3456, 3.4567])
s.cast(pl.Utf8, fmt="%0.2f") # fmt obviously isn't an argument
My current method is the following:
n = 2 # number of decimals desired
expr = pl.concat_str((
c.floor().cast(pl.Int32).cast(pl.Utf8),
pl.lit('.'),
((c%1)*(10**n)).round(0).cast(pl.Int32).cast(pl.Utf8)
)).str.ljust(width)
i.e separate the pre-decimal and post-decimal, format individually as strings, and concat together. Is there an easier way to do this?
Expected output:
shape: (3,)
Series: '' [str]
[
"1.23"
"2.34"
"3.45"
]