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

StringMethods.zfill(width: int) SeriesOrIndex[source]#

通过在Series/Index前面添加‘0’字符来填充字符串。

Series/Index 中的字符串在字符串的左侧填充 '0' 字符,以达到总字符串长度 width。Series/Index 中长度大于或等于 width 的字符串保持不变。

如果符号字符出现在字符串的第一个位置,则保留该符号字符。

Parameters:
widthint

结果字符串的最小长度; 长度小于宽度的字符串 将用‘0’字符填充。

Returns:
Series/Index of str dtype

返回在前面添加了‘0’字符的Series或Index。

另请参阅

rjust

用任意字符填充字符串的左侧。

ljust

用任意字符填充字符串的右侧。

pad

用任意字符填充字符串的指定边。

center

用任意字符填充字符串的两侧。

示例

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

请注意,None 不是字符串,因此它被转换为 None1000 保持不变,因为它比宽度长。

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