pandas.Series.str.center #
- 系列.str。中心( width , fillchar = ' ' ) [来源] #
填充系列/索引中字符串的左侧和右侧。
相当于
str.center()
。- 参数:
- 宽度整数
结果字符串的最小宽度;附加字符将用 填充
fillchar
。- 填充字符字符串
用于填充的附加字符,默认为空白。
- 返回:
- 对象的系列/索引。
例子
对于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