Fills the string with zeroes.
Description
Add zeroes to a string until it reaches n
characters. If
the number of characters is already greater than n
, the
string is not modified.
Usage
<Expr>$str$zfill(length)
Arguments
length
|
Pad the string until it reaches this length. Strings with length equal to or greater than this value are returned as-is. This can be an Expr or something coercible to an Expr. Strings are parsed as column names. |
Details
Return a copy of the string left filled with ASCII ‘0’ digits to make a string of length width.
A leading sign prefix (‘+’/‘-’) is handled by inserting the padding
after the sign character rather than before. The original string is
returned if width is less than or equal to len(s)
.
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(a = c(-1L, 123L, 999999L, NA))
df$with_columns(zfill = pl$col("a")$cast(pl$String)$str$zfill(4))
#> shape: (4, 2)
#> ┌────────┬────────┐
#> │ a ┆ zfill │
#> │ --- ┆ --- │
#> │ i32 ┆ str │
#> ╞════════╪════════╡
#> │ -1 ┆ -001 │
#> │ 123 ┆ 0123 │
#> │ 999999 ┆ 999999 │
#> │ null ┆ null │
#> └────────┴────────┘