@@ -1322,19 +1322,75 @@ def str_slice(arr, start=None, stop=None, step=None):
13221322
13231323def str_slice_replace (arr , start = None , stop = None , repl = None ):
13241324 """
1325- Replace a slice of each string in the Series/Index with another
1326- string.
1325+ Replace a positional slice of a string with another value.
13271326
13281327 Parameters
13291328 ----------
1330- start : int or None
1331- stop : int or None
1332- repl : str or None
1333- String for replacement
1329+ start : int, optional
1330+ Left index position to use for the slice. If not specified (None),
1331+ the slice is unbounded on the left, i.e. slice from the start
1332+ of the string.
1333+ stop : int, optional
1334+ Right index position to use for the slice. If not specified (None),
1335+ the slice is unbounded on the right, i.e. slice until the
1336+ end of the string.
1337+ repl : str, optional
1338+ String for replacement. If not specified (None), the sliced region
1339+ is replaced with an empty string.
13341340
13351341 Returns
13361342 -------
1337- replaced : Series/Index of objects
1343+ replaced : Series or Index
1344+ Same type as the original object.
1345+
1346+ See Also
1347+ --------
1348+ Series.str.slice : Just slicing without replacement.
1349+
1350+ Examples
1351+ --------
1352+ >>> s = pd.Series(['a', 'ab', 'abc', 'abdc', 'abcde'])
1353+ >>> s
1354+ 0 a
1355+ 1 ab
1356+ 2 abc
1357+ 3 abdc
1358+ 4 abcde
1359+ dtype: object
1360+
1361+ Specify just `start`, meaning replace `start` until the end of the
1362+ string with `repl`.
1363+
1364+ >>> s.str.slice_replace(1, repl='X')
1365+ 0 aX
1366+ 1 aX
1367+ 2 aX
1368+ 3 aX
1369+ 4 aX
1370+ dtype: object
1371+
1372+ Specify just `stop`, meaning the start of the string to `stop` is replaced
1373+ with `repl`, and the rest of the string is included.
1374+
1375+ >>> s.str.slice_replace(stop=2, repl='X')
1376+ 0 X
1377+ 1 X
1378+ 2 Xc
1379+ 3 Xdc
1380+ 4 Xcde
1381+ dtype: object
1382+
1383+ Specify `start` and `stop`, meaning the slice from `start` to `stop` is
1384+ replaced with `repl`. Everything before or after `start` and `stop` is
1385+ included as is.
1386+
1387+ >>> s.str.slice_replace(start=1, stop=3, repl='X')
1388+ 0 aX
1389+ 1 aX
1390+ 2 aX
1391+ 3 aXc
1392+ 4 aXde
1393+ dtype: object
13381394 """
13391395 if repl is None :
13401396 repl = ''
0 commit comments