Teradata Package for Python Function Reference | 20.00 - index - 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
lifecycle
latest
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.index = index(expression)
DESCRIPTION:
    Function returns the position in string values in column where string specified
    in the argument starts.
 
NOTES:
    a. If string in argument is not found in string in column, then the result is zero.
    b. If string in argument is null, then the result is null.
    c. If the arguments are character types, index returns a logical character position,
       not a byte position, except when the server character set of the arguments is KANJI1
       and the session client character set is KanjiEBCDIC.
 
PARAMETERS:
    expression:
        Required Argument.
        Specifies a ColumnExpression of a string column or a string literal
        which is used as a substring to be searched for its position within the
        full string in column.
        Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>'.
        Supported column types are:
            1. Character
            2. Byte - If value of column is of type BYTE, then "expression" must be of type BYTE.
            3. Numeric - If value of column is numeric, then it is converted implicitly to CHARACTER type.
        Types: ColumnExpression, str
 
RAISES:
    TypeError, ValueError, TeradataMlException
 
RETURNS:
    DataFrameColumn
 
EXAMPLES:
    # Load the data to execute 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: Returns the start position of "ce" in "stats" column and pass it as input
    #            to DataFrame.assign().
    >>> res = df.assign(col = df.stats.index("ner"))
    >>> print(res)
       masters   gpa     stats programming  admitted  col
    id
    3       no  3.70    Novice    Beginner         1    0
    4      yes  3.50  Beginner      Novice         1    6
    2      yes  3.76  Beginner    Beginner         0    6
    1      yes  3.95  Beginner    Beginner         0    6
 
    # Example 2: Executed index() function on "stats" column and filtered computed
    #            values which are equal to 0.
    >>> print(df[df.stats.index("ner") != 0])
       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