Teradata Package for Python Function Reference on VantageCloud Lake | 17.20 - otranslate - 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
 
 
otranslate

 
Functions
       
otranslate(source_string, from_string, to_string)
DESCRIPTION:
    Function returns source_string with every occurrence of each character in
    from_string replaced with the corresponding character in to_string.
 
    If the first character in from_string occurs in the source_string, all
    occurrences of it are replaced by the first character in to_string. This
    repeats for all characters in from_string and for all characters in
    to_string. The replacement is performed character-by-character, that is,
    the replacement of the second character is done on the string resulting
    from the replacement of the first character.
 
    If from_string contains more characters than to_string, the extra characters
    are removed from the source_string.
    If from_string contains fewer characters than to_string, the extra characters
    in to_string have no effect.
    If the same character occurs more than once in from_string, only the replacement
    character from the to_string corresponding to the first occurrence is used.
 
PARAMETERS:
    source_string:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal.
        If argument is NULL, NULL is returned.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
        Supported column types: CHAR, VARCHAR
 
    from_string:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        that will be replaced in source_string.
        If argument is NULL, the function returns source_string.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
        Supported column types: CHAR, VARCHAR
 
    to_string:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        that replaces the characters specified by from_string.
        If argument is NULL or empty, the function removes the characters
        specified in from_string.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
        Supported column types: CHAR, VARCHAR
 
NOTE:
    Function accepts positional arguments only.
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe", "admissions_train")
    >>>
 
    # Create a DataFrame on 'admissions_train' table.
    >>> admissions_train = DataFrame("admissions_train")
    >>> admissions_train
       masters   gpa     stats programming  admitted
    id
    22     yes  3.46    Novice    Beginner         0
    36      no  3.00  Advanced      Novice         0
    15     yes  4.00  Advanced    Advanced         1
    38     yes  2.65  Advanced    Beginner         1
    5       no  3.44    Novice      Novice         0
    17      no  3.83  Advanced    Advanced         1
    34     yes  3.85  Advanced    Beginner         0
    13      no  4.00  Advanced      Novice         1
    26     yes  3.57  Advanced    Advanced         1
    19     yes  1.98  Advanced    Advanced         0
    >>>
 
    # Example replaces the occurrence of from_string ('d') in the string in
    # "stats" column by the character in to_string ('X').
    # Import func from sqlalchemy to execute otranslate function.
    >>> from sqlalchemy import func
 
    # Create a sqlalchemy Function object.
    >>> otranslate_func_ = func.otranslate(admissions_train.stats.expression, "d", "X")
    >>>
 
    # Pass the Function object as input to DataFrame.assign().
    >>> df = admissions_train.assign(otranslate_stats_=otranslate_func_)
    >>> print(df)
       masters   gpa     stats programming  admitted otranslate_stats_
    id
    22     yes  3.46    Novice    Beginner         0            Novice
    26     yes  3.57  Advanced    Advanced         1          AXvanceX
    5       no  3.44    Novice      Novice         0            Novice
    17      no  3.83  Advanced    Advanced         1          AXvanceX
    13      no  4.00  Advanced      Novice         1          AXvanceX
    19     yes  1.98  Advanced    Advanced         0          AXvanceX
    36      no  3.00  Advanced      Novice         0          AXvanceX
    15     yes  4.00  Advanced    Advanced         1          AXvanceX
    34     yes  3.85  Advanced    Beginner         0          AXvanceX
    38     yes  2.65  Advanced    Beginner         1          AXvanceX
    >>>