Teradata Package for Python Function Reference on VantageCloud Lake - substring_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 on VantageCloud Lake
- Deployment
- VantageCloud
- Edition
- Lake
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.08
- Published
- November 2025
- ft:locale
- en-US
- ft:lastEdition
- 2025-12-05
- dita:id
- TeradataPython_FxRef_Lake_2000
- Product Category
- Teradata Vantage
- teradataml.dataframe.sql.DataFrameColumn.substring_index = substring_index(self, delimiter, count)
- DESCRIPTION:
Function to return the substring from a column before a specified
delimiter, up to a given occurrence count.
PARAMETERS:
delimiter:
Required Argument.
Specifies the delimiter string to split the column values.
Types: str
count:
Required Argument.
Specifies the number of occurrences of the delimiter to consider.
If positive, the substring is extracted from the start of the string.
If negative, the substring is extracted from the end of the string.
If zero, an empty string is returned.
Types: int
RAISES:
TeradataMlException
RETURNS:
ColumnExpression.
EXAMPLES:
# Load the data to run the example.
>>> load_example_data("dataframe","admissions_train")
>>> df = DataFrame('admissions_train')
# Create a new column 'delim_col' with string.
>>> df1 = df.assign(delim_col = 'ab.c.def.g')
>>> df1
masters gpa stats programming admitted delim_col
id
38 yes 2.65 Advanced Beginner 1 ab.c.def.g
7 yes 2.33 Novice Novice 1 ab.c.def.g
26 yes 3.57 Advanced Advanced 1 ab.c.def.g
5 no 3.44 Novice Novice 0 ab.c.def.g
3 no 3.70 Novice Beginner 1 ab.c.def.g
22 yes 3.46 Novice Beginner 0 ab.c.def.g
1 yes 3.95 Beginner Beginner 0 ab.c.def.g
17 no 3.83 Advanced Advanced 1 ab.c.def.g
15 yes 4.00 Advanced Advanced 1 ab.c.def.g
34 yes 3.85 Advanced Beginner 0 ab.c.def.g
# Example 1: Create a new column 'new_column' by extracting the substring
based on positive count.
>>> res = df1.assign(new_column = df1.delim_col.substring_index('.', 2))
>>> res
masters gpa stats programming admitted delim_col new_column
id
34 yes 3.85 Advanced Beginner 0 ab.c.def.g ab.c
32 yes 3.46 Advanced Beginner 0 ab.c.def.g ab.c
11 no 3.13 Advanced Advanced 1 ab.c.def.g ab.c
30 yes 3.79 Advanced Novice 0 ab.c.def.g ab.c
28 no 3.93 Advanced Advanced 1 ab.c.def.g ab.c
16 no 3.70 Advanced Advanced 1 ab.c.def.g ab.c
35 no 3.68 Novice Beginner 1 ab.c.def.g ab.c
40 yes 3.95 Novice Beginner 0 ab.c.def.g ab.c
19 yes 1.98 Advanced Advanced 0 ab.c.def.g ab.c
# Example 2: Create a new column 'new_column' by extracting the substring
based on negative count.
>>> res = df1.assign(new_column = df1.delim_col.substring_index('.', -3))
>>> res
masters gpa stats programming admitted delim_col new_column
id
34 yes 3.85 Advanced Beginner 0 ab.c.def.g c.def.g
32 yes 3.46 Advanced Beginner 0 ab.c.def.g c.def.g
11 no 3.13 Advanced Advanced 1 ab.c.def.g c.def.g
30 yes 3.79 Advanced Novice 0 ab.c.def.g c.def.g
28 no 3.93 Advanced Advanced 1 ab.c.def.g c.def.g
16 no 3.70 Advanced Advanced 1 ab.c.def.g c.def.g
35 no 3.68 Novice Beginner 1 ab.c.def.g c.def.g
40 yes 3.95 Novice Beginner 0 ab.c.def.g c.def.g
19 yes 1.98 Advanced Advanced 0 ab.c.def.g c.def.g
# Example 3: Create a new column 'new_column' by extracting the substring
with 2-character delimiter based on positive count.
>>> res = df1.assign(new_column = df1.delim_col.substring_index('c.d', 1))
>>> res
masters gpa stats programming admitted delim_col new_column
id
34 yes 3.85 Advanced Beginner 0 ab.c.def.g ab.
32 yes 3.46 Advanced Beginner 0 ab.c.def.g ab.
11 no 3.13 Advanced Advanced 1 ab.c.def.g ab.
30 yes 3.79 Advanced Novice 0 ab.c.def.g ab.
28 no 3.93 Advanced Advanced 1 ab.c.def.g ab.
16 no 3.70 Advanced Advanced 1 ab.c.def.g ab.
35 no 3.68 Novice Beginner 1 ab.c.def.g ab.
40 yes 3.95 Novice Beginner 0 ab.c.def.g ab.