Examples

In [1]:
import numpy as np
import pandas as pd
In [2]:
s = pd.Series(['p', 'pq', 'pqr', 'pqsr', 'pqrst'])
s
Out[2]:
0        p
1       pq
2      pqr
3     pqsr
4    pqrst
dtype: object

Specify just start, meaning replace start until the end of the string with repl.

In [3]:
s.str.slice_replace(1, repl='A')
Out[3]:
0    pA
1    pA
2    pA
3    pA
4    pA
dtype: object

Specify just stop, meaning the start of the string to stop is replaced with repl, and the rest
of the string is included.

In [4]:
s.str.slice_replace(stop=2, repl='A')
Out[4]:
0       A
1       A
2      Ar
3     Asr
4    Arst
dtype: object

Specify start and stop, meaning the slice from start to stop is replaced with repl.
Everything before or after start and stop is included as is.

In [5]:
s.str.slice_replace(start=1, stop=3, repl='A')
Out[5]:
0      pA
1      pA
2      pA
3     pAr
4    pAst
dtype: object