pandas 1.4.2

ParametersReturns
slice_replace(self, start=None, stop=None, repl=None)

Parameters

start : int, optional

Left index position to use for the slice. If not specified (None), the slice is unbounded on the left, i.e. slice from the start of the string.

stop : int, optional

Right index position to use for the slice. If not specified (None), the slice is unbounded on the right, i.e. slice until the end of the string.

repl : str, optional

String for replacement. If not specified (None), the sliced region is replaced with an empty string.

Returns

Series or Index

Same type as the original object.

Replace a positional slice of a string with another value.

See Also

Series.str.slice

Just slicing without replacement.

Examples

This example is valid syntax, but we were not able to check execution
>>> s = pd.Series(['a', 'ab', 'abc', 'abdc', 'abcde'])
... s 0 a 1 ab 2 abc 3 abdc 4 abcde dtype: object

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

This example is valid syntax, but we were not able to check execution
>>> s.str.slice_replace(1, repl='X')
0    aX
1    aX
2    aX
3    aX
4    aX
dtype: object

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

This example is valid syntax, but we were not able to check execution
>>> s.str.slice_replace(stop=2, repl='X')
0       X
1       X
2      Xc
3     Xdc
4    Xcde
dtype: object

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

This example is valid syntax, but we were not able to check execution
>>> s.str.slice_replace(start=1, stop=3, repl='X')
0      aX
1      aX
2      aX
3     aXc
4    aXde
dtype: object
See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/strings/accessor.py#1753
type: <class 'function'>
Commit: