mars.dataframe.Series.str.zfill#

Series.str.zfill(width)#

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

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

Parameters

宽度 (int) – 结果字符串的最小长度;长度小于 宽度 的字符串将在前面追加‘0’字符。

Return type

对象的序列/索引。

另请参阅

Series.str.rjust

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

Series.str.ljust

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

Series.str.pad

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

Series.str.center

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

备注

str.zfill() 不同,它对字符串中的‘+’/’-’有特殊处理。

示例

>>> import mars.tensor as mt
>>> import mars.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     0-1
1     001
2    1000
3     NaN
4     NaN
dtype: object