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
teradataml.dataframe.sql.DataFrameColumn.otranslate = otranslate(expression, replace_string)
DESCRIPTION:
    Function returns values in column with every occurrence of each character in
    "expression" replaced with the corresponding character in "replace_string".
 
    If the first character in "expression" occurs in the values in column, all
    occurrences of it are replaced by the first character in "replace_string". This
    repeats for all characters in "expression" and for all characters in
    "replace_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 "expression" contains more characters than "replace_string", the extra characters
    are removed from the string values in column.
    If "expression" contains fewer characters than "replace_string", the extra characters
    in "replace_string" have no effect.
    If the same character occurs more than once in "expression", only the replacement
    character from the "replace_string" corresponding to the first occurrence is used.
 
ALTERNATE NAME:
    translate
 
PARAMETERS:
    expression:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        that will be replaced in string values in column.
        If argument is NULL, the function returns string values in column.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
        Supported column types: CHAR, VARCHAR
        Types: ColumnExpression, str
 
    replace_string:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        that replaces the characters specified by expression.
        If argument is NULL or empty, the function removes the characters
        specified in expression.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>'.
        Supported column types: CHAR, VARCHAR
        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: Replaces the occurrence of 'i' in the string in "stats" column by the
    # character in to_string ('X') and pass it as input to DataFrame.assign().
    >>> res = df.assign(col = df.stats.otranslate("i", "X"))
    >>> print(res)
       masters   gpa     stats programming  admitted       col
    id
    3       no  3.70    Novice    Beginner         1    NovXce
    4      yes  3.50  Beginner      Novice         1  BegXnner
    2      yes  3.76  Beginner    Beginner         0  BegXnner
    1      yes  3.95  Beginner    Beginner         0  BegXnner
 
    # Example 2: Executed otranslate() function on "stats" column and filtered computed
    # values which are equal to 'BegXnner'.
    >>> print(df[df.stats.otranslate("i", "X") == "BegXnner"])
       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