Teradata Package for Python Function Reference | 20.00 - 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 - 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.instr = instr(expression, position=1, occurrence=1)
- DESCRIPTION:
Function searches the string values in column for occurrences of "expression".
PARAMETERS:
expression:
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>'.
Types: ColumnExpression, str
position:
Optional Argument.
Specifies the position as an integer to begin searching at in the string values in column.
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.
Default Value: 1
Types: int
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.
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.
>>> 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: Searches for a string 'e' in "programming" column values and pass it
# as input to DataFrame.assign().
>>> res = df.assign(col = df.programming.instr("e"))
>>> print(res)
masters gpa stats programming admitted col
id
3 no 3.70 Novice Beginner 1 2.0
4 yes 3.50 Beginner Novice 1 6.0
2 yes 3.76 Beginner Beginner 0 2.0
1 yes 3.95 Beginner Beginner 0 2.0
# Example 2: Executed instr() function on "programming" column and filtered computed
# values which are equal to 6.0.
>>> print(df[df.programming.instr("e") == 6.0])
masters gpa stats programming admitted
id
4 yes 3.5 Beginner Novice 1