maxframe.dataframe.Series.str.zfill#

Series.str.zfill(width: int)#

通过在字符串前面添加 '0' 字符来填充 Series/Index 中的字符串。

Series/Index 中的字符串会在左侧添加 '0' 字符,使其总长度达到 width。长度大于或等于 width 的字符串将保持不变。

参数:

width (int) -- 结果字符串的最小长度;长度小于 width 的字符串将在前面添加 '0' 字符。

返回:

A Series or Index where the strings are prepended with '0' characters.

返回类型:

Series/Index of objects.

参见

Series.str.rjust

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

Series.str.ljust

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

Series.str.pad

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

Series.str.center

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

备注

str.zfill() 不同,后者对字符串中的 '+'/'-' 有特殊处理。

示例

>>> import maxframe.tensor as mt
>>> import maxframe.dataframe as md
>>> s = md.Series(["-1", "1", "1000", 10, mt.nan])
>>> s.execute()
0      -1
1       1
2    1000
3      10
4     NaN
dtype: object

注意 10NaN 不是字符串,因此它们会被转换为 NaN'-1' 中的负号被视为特殊字符,零被添加到它的右侧(str.zfill() 会将其移到左侧)。1000 保持不变,因为它的长度超过了 width

>>> s.str.zfill(3).execute()
0     -01
1     001
2    1000
3     NaN
4     NaN
dtype: object