Loading...

vastorbit.VastColumn.str_replace

VastColumn.str_replace(to_replace: str, value: str | None = None) VastFrame

Replaces the regular expression matches in each of the VastColumn record by an input value. The VastColumn will be transformed.

Parameters:
  • to_replace (str) – Regular expression to replace.

  • value (str, optional) – New value.

Returns:

self._parent

Return type:

VastFrame

Examples

Let’s begin by importing vastorbit.

import vastorbit as vo

Let’s generate a small dataset using the following data:

data = vo.VastFrame(
    {
        "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  = r"([A-Za-z])+\.",
    value = "[Name_Prefix]"
)
Abc
name
Varchar(2479)
1[Name_Prefix] Helen Ross
2[Name_Prefix] Charlie Dickens
3[Name_Prefix] Jack Smith
4[Name_Prefix] Steve Smith
Rows: 1-4 | Column: name | Type: varchar(2479)

See also

VastFrame.str_contains() : Validates the regular expression.
VastFrame.str_count() : Counts occurrences matching the regular expression.
VastFrame.str_extract() : Extracts the Regular Expression.
VastFrame.str_slice() : Slices the Regular Expression.