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

Product
Teradata Package for Python
Release Number
17.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
instr

 
Functions
       
instr(source_string, search_string, position, occurrence)
DESCRIPTION:
    Function searches the source_string argument for occurrences of search_string.
 
PARAMETERS:
    source_string:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
 
    search_string:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        that the function searches for in source_string.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>.expression'.
 
    position:
        Optional Argument.
        Specifies the position as an integer to begin searching at in the source_string.
        If position is not specified, the search starts at the beginning of source_string.
        If position is negative, the function counts and searches backwards from the end of
        source_string.
        It cannot have a value of zero.
 
    occurrence:
        Optional Argument.
        Specifies an integer which decides occurrence of search_string to find in source_string.
        If occurrence is not specified, the function searches for the first occurrence.
        If occurrence is greater than 1, the function searches for additional occurrences
        beginning with the second character in the previous occurrence.
        It cannot be zero or a negative value.
 
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 searches for a string "e" in "programming" column values.
    # Import func from sqlalchemy to execute instr function.
    >>> from sqlalchemy import func
 
    # Create a sqlalchemy Function object.
    >>> instr_func_ = func.instr(admissions_train.programming.expression, "e")
    >>>
 
    # Pass the Function object as input to DataFrame.assign().
    >>> df = admissions_train.assign(instr_e_in_programming_=instr_func_)
    >>> print(df)
       masters   gpa     stats programming  admitted instr_e_in_programming_
    id
    15     yes  4.00  Advanced    Advanced         1                       7
    7      yes  2.33    Novice      Novice         1                       6
    22     yes  3.46    Novice    Beginner         0                       2
    17      no  3.83  Advanced    Advanced         1                       7
    13      no  4.00  Advanced      Novice         1                       6
    38     yes  2.65  Advanced    Beginner         1                       2
    26     yes  3.57  Advanced    Advanced         1                       7
    5       no  3.44    Novice      Novice         0                       6
    34     yes  3.85  Advanced    Beginner         0                       2
    40     yes  3.95    Novice    Beginner         0                       2
    >>>