Teradata Package for Python Function Reference on VantageCloud Lake - slice - 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.11
Published
August 2026
ft:locale
en-US
ft:lastEdition
2026-08-13
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.slice = slice(self, start, length)
DESCRIPTION:
    Slice the array from the specified starting index for the given length.
 
PARAMETERS:
    start:
        Required Argument.
        Specifies the starting index (1-based) for slicing.
        Note:
            * If start is negative, the slice starts from the end of the array.
        Types: ColumnExpression OR int
        
    length:
        Required Argument.
        Specifies the number of elements to include in the slice.
        Types: ColumnExpression OR int
 
RETURNS:
    ColumnExpression
 
EXAMPLES:
    >>> from teradataml import *
    >>> load_example_data("array", "array_table")
 
    # Create a DataFrame on 'array_table'.
    >>> df = DataFrame("array_table")
    >>> df
                     arr1                   arr2                        arr3
    id                                                                      
    1    (10,20,30,40,50)     (23,200,215,40,21)  ('ab','bc','cd','ab','ef')
    4   (180,28,38,48,58)  (30,NULL,NULL,250,27)  ('mn','no',NULL,'op','pq')
    2   (150,25,35,45,55)       (28,50,95,90,26)  ('xy','yz','za','ab','xy')
    6   (16,261,36,46,56)     (29,170,160,46,25)  ('uv','xy','ab','xy','yz')
    3   (12,22,320,42,52)     (25,22,140,200,23)  ('pq','ab','ab','st','tu')
    5    (14,24,34,44,54)  (26,NULL,NULL,180,24)  ('ij','jk',NULL,'kl','lm')
 
    # Example 1: Slice array column 'arr1' starting from index 2 for length 3.
    >>> res = df.assign(sliced_arr = df.arr1.slice(start=2, length=3))
    >>> res
                     arr1                   arr2                        arr3   sliced_arr
    id                                                                                   
    1    (10,20,30,40,50)     (23,200,215,40,21)  ('ab','bc','cd','ab','ef')   (20,30,40)
    3   (12,22,320,42,52)     (25,22,140,200,23)  ('pq','ab','ab','st','tu')  (22,320,42)
    6   (16,261,36,46,56)     (29,170,160,46,25)  ('uv','xy','ab','xy','yz')  (261,36,46)
    2   (150,25,35,45,55)       (28,50,95,90,26)  ('xy','yz','za','ab','xy')   (25,35,45)
    5    (14,24,34,44,54)  (26,NULL,NULL,180,24)  ('ij','jk',NULL,'kl','lm')   (24,34,44)
    4   (180,28,38,48,58)  (30,NULL,NULL,250,27)  ('mn','no',NULL,'op','pq')   (28,38,48)
 
    # Example 2: Slice array column 'arr2' using ColumnExpression for start and length.
    >>> tdf = df.assign(start_index=-3, slice_length=2)
    >>> res = tdf.assign(sliced_arr = tdf.arr2.slice(tdf.start_index, tdf.slice_length))
    >>> res
                                arr1                   arr2                        arr3  slice_length  start_index  sliced_arr
    id                                                                                                             
    5    (14,24,34,44,54)  (26,NULL,NULL,180,24)  ('ij','jk',NULL,'kl','lm')             2           -3  (NULL,180)
    2   (150,25,35,45,55)       (28,50,95,90,26)  ('xy','yz','za','ab','xy')             2           -3     (95,90)
    4   (180,28,38,48,58)  (30,NULL,NULL,250,27)  ('mn','no',NULL,'op','pq')             2           -3  (NULL,250)
    1    (10,20,30,40,50)     (23,200,215,40,21)  ('ab','bc','cd','ab','ef')             2           -3    (215,40)
    3   (12,22,320,42,52)     (25,22,140,200,23)  ('pq','ab','ab','st','tu')             2           -3   (140,200)
    6   (16,261,36,46,56)     (29,170,160,46,25)  ('uv','xy','ab','xy','yz')             2           -3    (160,46)