cudf.core.column.string.StringMethods.zfill#

StringMethods.zfill(width: int) SeriesOrIndex#

Pad strings in the Series/Index by prepending ‘0’ characters.

Strings in the Series/Index are padded with ‘0’ characters on the left of the string to reach a total string length width. Strings in the Series/Index with length greater or equal to width are unchanged.

The sign character is preserved if it appears in the first position of the string.

Parameters:
widthint

Minimum length of resulting string; strings with length less than width be prepended with ‘0’ characters.

Returns:
Series/Index of str dtype

Returns Series or Index with prepended ‘0’ characters.

See also

rjust

Fills the left side of strings with an arbitrary character.

ljust

Fills the right side of strings with an arbitrary character.

pad

Fills the specified sides of strings with an arbitrary character.

center

Fills both sides of strings with an arbitrary character.

Examples

>>> import cudf
>>> s = cudf.Series(['-1', '1', '1000',  None])
>>> s
0      -1
1       1
2    1000
3    <NA>
dtype: object

Note that None is not string, therefore it is converted to None. 1000 remains unchanged as it is longer than width.

>>> s.str.zfill(3)
0     -01
1     001
2    1000
3    <NA>
dtype: object