Teradata Package for Python Function Reference | 20.00 - 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 - 20.00

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
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_Enterprise_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
 
    length:
        Required Argument.
        Specifies the length of the string to extract from column.
        Types: int
 
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