cudf.core.column.string.StringMethods.center#

StringMethods.center(width: int, fillchar: str = ' ') SeriesOrIndex[source]#

在Series/Index的字符串左右两侧填充额外的字符。

Parameters:
widthint

结果字符串的最小宽度; 额外的字符将用 fillchar 填充。

fillcharstr, default is ‘ ‘ (whitespace)

用于填充的额外字符。

Returns:
Series/Index of str dtype

返回 Series 或 Index。

示例

>>> import cudf
>>> s = cudf.Series(['a', 'b', None, 'd'])
>>> s.str.center(1)
0       a
1       b
2    <NA>
3       d
dtype: object
>>> s.str.center(1, fillchar='-')
0       a
1       b
2    <NA>
3       d
dtype: object
>>> s.str.center(2, fillchar='-')
0      a-
1      b-
2    <NA>
3      d-
dtype: object
>>> s.str.center(5, fillchar='-')
0    --a--
1    --b--
2     <NA>
3    --d--
dtype: object
>>> s.str.center(6, fillchar='-')
0    --a---
1    --b---
2      <NA>
3    --d---
dtype: object