Skip to content

LazyColumn.str.zfill

zfill

zfill(width: int) -> LazyColumn

Pads each string in the column on the left with zeros ('0') to make it of specified width.

Parameters:

Name Type Description Default
width int

The total width of the resulting string after padding.

required

Returns:

Name Type Description
LazyColumn LazyColumn

A new LazyColumn with the strings left-padded with '0' to the given width.

Examples:

print(df.head())
#    col1 my_string_column
# 0     1         "abc"
# 1     2         "1234"
# 2     3         None
# 3     4         "5"
# 4     5         "xyz"

df["my_string_column"].str.zfill(4)
# ["0abc", "1234", None, "0005", "0xyz"]