Teradata Package for Python Function Reference on VantageCloud Lake - substr - 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.11
Publication Date
August 2026
Content Type
Programming Reference
Publication ID
B700-4500-200K
ft:locale
en-US
ft:lastEdition
2026-08-13
ft:sourceId
FTML
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.substr = substr(self, start_pos, length)
DESCRIPTION:
    Function to get substring from column.
 
PARAMETERS:
    start_pos:
        Required Argument.
        Specifies starting position to extract string from column.
        Note:
            Index position starts with 1 instead of 0.
        Types: int OR ColumnExpression
 
    length:
        Required Argument.
        Specifies the length of the string to extract from column.
        Types: int OR ColumnExpression
 
RETURNS:
    ColumnExpression.
 
EXAMPLES:
    >>> load_example_data("ntree", "employee_table")
    >>> df = DataFrame("employee_table")
           emp_name  mgr_id mgr_name
    emp_id
    200         Pat   100.0      Don
    300       Donna   100.0      Don
    400         Kim   200.0      Pat
    500        Fred   400.0      Kim
    100         Don     NaN       NA
 
    # Example 1: Create a new column by extracting the first 3 letters
    #            from column emp_name.
    >>> df.assign(new_column = df.emp_name.substr(1,3))
           emp_name  mgr_id mgr_name new_column
    emp_id
    200         Pat   100.0      Don        Pat
    300       Donna   100.0      Don        Don
    400         Kim   200.0      Pat        Kim
    500        Fred   400.0      Kim        Fre
    100         Don     NaN       NA        Don
 
    # Example 2: Find out the employees whose first three letters
    #            in their name is 'Fre'.
    >>> df[df.emp_name.substr(1,3) == 'Fre']
           emp_name  mgr_id mgr_name new_col
    emp_id
    500        Fred     400      Kim      on
 
    # Example 3: Create a new column by passing ColumnExpression as
    #            start_pos and length.
    >>> df.assign(new_column = df.emp_name.substr(df.emp_id, df.mgr_id))
             emp_name  mgr_id mgr_name new_column
    emp_id
    1         Pat   2      Don        Pa