pandas.Series.str.center

Filling left and right side of strings in the Series/Index with an additional character. Equivalent to str.center().

param width
int

Minimum width of resulting string; additional characters will be filled with fillchar

param fillchar
str

Additional character for filling, default is whitespace

return

filled : Series/Index of objects

Examples

Filling left and right side of strings in the Series with an additional character
import pandas as pd
from numba import njit


@njit
def series_str_center():
    series = pd.Series(['dog', 'foo', 'bar'])  # Series of 'dog', 'foo', 'bar'
    out_series = series.str.center(5, '*')

    return out_series  # Expect series of '*dog*', '*foo*', '*bar*'


print(series_str_center())
$ python ./series/str/series_str_center.py
0    *dog*
1    *foo*
2    *bar*
dtype: object

See also

Series.str.rjust

Fills the left side of strings with an arbitrary character.

Series.str.ljust

Fills the right side of strings with an arbitrary character.

Todo

Add support of 32-bit Unicode for str.center()