verticapy.vDataColumn.str_replace¶
- vDataColumn.str_replace(to_replace: str, value: str | None = None) vDataFrame¶
Replaces the regular expression matches in each of the vDataColumn record by an input value. The vDataColumn will be transformed.
Parameters¶
- to_replace: str
Regular expression to replace.
- value: str, optional
New value.
Returns¶
- vDataFrame
self._parent
Examples¶
Let’s begin by importing VerticaPy.
import verticapy as vp
Let’s generate a small dataset using the following data:
data = vp.vDataFrame( { "name": [ 'Mr. Steve Smith', 'Mr. Charlie Dickens', 'Mrs. Helen Ross', 'Dr. Jack Smith', ] } )
Let’s replace the name prefix with static text “[Name_Prefix]”.
data["name"].str_replace( to_replace = "([A-Za-z])+\.", value = "[Name_Prefix]" )
Abcname100%1 [Name_Prefix] Steve Smith 2 [Name_Prefix] Charlie Dickens 3 [Name_Prefix] Helen Ross 4 [Name_Prefix] Jack Smith See also
vDataFrame.str_contains(): Validates the regular expression.vDataFrame.str_count(): Counts occurrences matching the regular expression.vDataFrame.str_extract(): Extracts the Regular Expression.vDataFrame.str_slice(): Slices the Regular Expression.