Teradata Package for Python Function Reference on VantageCloud Lake | 17.20 - oreplace - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.

Teradata® Package for Python Function Reference on VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Package for Python
Release Number
17.20
Publication Date
November 2022
Content Type
Programming Reference
Publication ID
B700-4500-112K
ft:locale
en-US
ft:lastEdition
2024-02-21
ft:sourceId
FTML
dita:id
TeradataPython_FxRef_Lake_1720
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.oreplace = oreplace(search_string, replace_string)
DESCRIPTION:
    Function replaces every occurrence of "search_string" in the string value in column
    with the "replace_string". Use this function either to replace or remove
    portions of a string.
 
ALTERNATE NAME:
    replace
 
PARAMETERS:
    search_string:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        that the function searches for string values in column.
        If argument is null, then result is null.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>'.
        Supported column types: CHAR, VARCHAR, or CLOB
        Types: ColumnExpression, str
 
    replace_string:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        that replaces the characters specified by "search_string".
        If argument is NULL or is an empty string, or is omitted, all
        occurrences of "search_string" are removed from the string values in column.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>'.
        Supported column types: CHAR, VARCHAR, or CLOB
        Types: ColumnExpression, str
 
RAISES:
    TypeError, ValueError, TeradataMlException
 
RETURNS:
    DataFrameColumn
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe", "admissions_train")
 
    # Create a DataFrame on 'admissions_train' table.
    >>> df = DataFrame("admissions_train").iloc[:4]
    >>> print(df)
       masters   gpa     stats programming  admitted
    id
    3       no  3.70    Novice    Beginner         1
    4      yes  3.50  Beginner      Novice         1
    2      yes  3.76  Beginner    Beginner         0
    1      yes  3.95  Beginner    Beginner         0
 
    # Example 1: Removes occurrence of 'ner' in "stats" column and pass it as
    #            input to DataFrame.assign().
    >>> res = df.assign(col = df.stats.oreplace("ner"))
    >>> print(res)
       masters   gpa     stats programming  admitted     col
    id
    3       no  3.70    Novice    Beginner         1  Novice
    4      yes  3.50  Beginner      Novice         1  Begin
    2      yes  3.76  Beginner    Beginner         0  Begin
    1      yes  3.95  Beginner    Beginner         0  Begin
 
    # Example 2: Executed oreplace() function on "stats" column and filtered computed
    #            values which are equal to 'Begin'.
    >>> print(df[df.stats.oreplace("ner") == "Begin"])
       masters   gpa     stats programming  admitted
    id
    4      yes  3.50  Beginner      Novice         1
    2      yes  3.76  Beginner    Beginner         0
    1      yes  3.95  Beginner    Beginner         0