pandas.Series.str.center#

Series.str.center(width, fillchar=' ')[源代码]#

填充 Series/Index 中的字符串的左右两侧。

等同于 str.center()

Parameters:
widthint

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

fillcharstr

用于填充的附加字符,默认为空格。

Returns:
对象 Series/Index。

Examples

对于 Series.str.center:

>>> ser = pd.Series(['dog', 'bird', 'mouse'])
>>> ser.str.center(8, fillchar='.')
0   ..dog...
1   ..bird..
2   .mouse..
dtype: object

对于 Series.str.ljust:

>>> ser = pd.Series(['dog', 'bird', 'mouse'])
>>> ser.str.ljust(8, fillchar='.')
0   dog.....
1   bird....
2   mouse...
dtype: object

对于 Series.str.rjust:

>>> ser = pd.Series(['dog', 'bird', 'mouse'])
>>> ser.str.rjust(8, fillchar='.')
0   .....dog
1   ....bird
2   ...mouse
dtype: object