Teradata Package for Python Function Reference on VantageCloud Lake - trim - 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
20.00.00.03
Published
December 2024
ft:locale
en-US
ft:lastEdition
2024-12-19
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.trim = trim(self, expression=' ')
DESCRIPTION:
    Function trims the string values in the column.
 
PARAMETERS:
    expression:
        Optional Argument.
        Specifies a ColumnExpression of a string column or a string literal to
        be trimmed. If "expression" is specified, it must be the same data type
        as string values in column.
        Default Value: ' '
        Type: str or ColumnExpression
 
RAISES:
    TypeError, ValueError, TeradataMlException
 
RETURNS:
    ColumnExpression
 
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")
    >>> df
        masters   gpa     stats programming  admitted
    id
    38     yes  2.65  Advanced    Beginner         1
    7      yes  2.33    Novice      Novice         1
    26     yes  3.57  Advanced    Advanced         1
    5       no  3.44    Novice      Novice         0
    3       no  3.70    Novice    Beginner         1
    22     yes  3.46    Novice    Beginner         0
    24      no  1.87  Advanced      Novice         1
    36      no  3.00  Advanced      Novice         0
    19     yes  1.98  Advanced    Advanced         0
    40     yes  3.95    Novice    Beginner         0
 
    # Example 1: Trim "Begi" from the strings in column "programing".
    >>> res = df.assign(trim_col = df.programming.trim("Begi"))
    >>> res
        masters   gpa     stats programming  admitted  trim_col
    id
    38     yes  2.65  Advanced    Beginner         1      nner
    7      yes  2.33    Novice      Novice         1     Novic
    26     yes  3.57  Advanced    Advanced         1  Advanced
    5       no  3.44    Novice      Novice         0     Novic
    3       no  3.70    Novice    Beginner         1      nner
    22     yes  3.46    Novice    Beginner         0      nner
    24      no  1.87  Advanced      Novice         1     Novic
    36      no  3.00  Advanced      Novice         0     Novic
    19     yes  1.98  Advanced    Advanced         0  Advanced
    40     yes  3.95    Novice    Beginner         0      nner
 
    # Example 2: Filter the rows where values in the column "programming" result
    #            in "nner" after it is trimmed with 'Begi'.
    >>> df[df.programming.trim("Begi") == "nner"]
        masters   gpa     stats programming  admitted
    id
    3       no  3.70    Novice    Beginner         1
    1      yes  3.95  Beginner    Beginner         0
    39     yes  3.75  Advanced    Beginner         0
    34     yes  3.85  Advanced    Beginner         0
    35      no  3.68    Novice    Beginner         1
    31     yes  3.50  Advanced    Beginner         1
    29     yes  4.00    Novice    Beginner         0
    32     yes  3.46  Advanced    Beginner         0
    22     yes  3.46    Novice    Beginner         0
    38     yes  2.65  Advanced    Beginner         1
 
    # Example 3: Trim string in "programing" column using "masters" column as argument.
    >>> res = df.assign(trim_col = df.programming.trim(df.masters))
    >>> res
        masters   gpa     stats programming  admitted  trim_col
    id
    38     yes  2.65  Advanced    Beginner         1  Beginner
    7      yes  2.33    Novice      Novice         1     Novic
    26     yes  3.57  Advanced    Advanced         1  Advanced
    17      no  3.83  Advanced    Advanced         1  Advanced
    34     yes  3.85  Advanced    Beginner         0  Beginner
    13      no  4.00  Advanced      Novice         1    Novice
    32     yes  3.46  Advanced    Beginner         0  Beginner
    11      no  3.13  Advanced    Advanced         1  Advanced
    15     yes  4.00  Advanced    Advanced         1  Advanced
    36      no  3.00  Advanced      Novice         0    Novice