Teradata Package for Python Function Reference | 20.00 - locate - 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.locate = locate(expression, n1=1)
- DESCRIPTION:
Function returns the position of the first occurrence of string values in column within
value specified in argument.
PARAMETERS:
expression:
Required Argument.
Specifies a ColumnExpression of a string column or a string literal for
the full string to be searched in values in column.
Format of a ColumnExpression of a string column: '<dataframe>.<dataframe_column>'.
Support types of arguments:
1. Character, except for CLOB
2. Byte, except for BLOB
If value of column is of type BYTE, then "expression" must be of type BYTE.
3. Numeric - This is converted implicitly to CHARACTER type.
Types: ColumnExpression, str
n1:
Optional Argument.
Specifies where the search begins with the character position indicated by the
value of n1. Accepts a positive integer value.
Default Value: 1
Types: int
RAISES:
TypeError, ValueError, TeradataMlException
RETURNS:
DataFrameColumn
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
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 position of string in "stats" column in a string
# 'novicebeginner' and pass it as input to DataFrame.assign().
>>> res = df.assign(col = df.stats.locate("novicebeginner"))
>>> print(res)
masters gpa stats programming admitted col
id
3 no 3.70 Novice Beginner 1 1
4 yes 3.50 Beginner Novice 1 7
2 yes 3.76 Beginner Beginner 0 7
1 yes 3.95 Beginner Beginner 0 7
# Example 2: Executed locate() function on "stats" column and filtered computed
# values which are equal to 1.
>>> print(df[df.stats.locate("novicebeginner") == 1])
masters gpa stats programming admitted
id
3 no 3.7 Novice Beginner 1