pandas.Series.str.zfill

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.

param width
int

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

return

Series/Index of objects

Limitations

A leading sign prefix (‘+’/’-‘) is handled by inserting the padding after the sign character rather than before.

Examples

Pad strings in the Series by prepending ‘0’ characters
import pandas as pd
from numba import njit


@njit
def series_str_zfill():
    series = pd.Series(['dog', 'foo', 'bar'])  # Series of 'dog', 'foo', 'bar'
    out_series = series.str.zfill(5)

    return out_series  # Expect series of '00dog', '00foo', '00bar'


print(series_str_zfill())
$ python ./series/str/series_str_zfill.py
0    00dog
1    00foo
2    00bar
dtype: object

See also

Series.str.rjust

Fills the left side of strings with an arbitrary character.

Series.str.ljust

Fills the right side of strings with an arbitrary character.

Series.str.pad

Fills the specified sides of strings with an arbitrary character.

Series.str.center

Fills boths sides of strings with an arbitrary character.

Todo

Add support of 32-bit Unicode for str.zfill()