Teradata Package for Python Function Reference on VantageCloud Lake - subbitstr - 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.03
Published
December 2024
ft:locale
en-US
ft:lastEdition
2024-12-19
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.subbitstr = subbitstr(position, num_bits)
DESCRIPTION:
    Function extracts a bit substring from the integer or byte column
    based on the specified bit position. Function returns a VARBYTE string,
    thus resulting number of bits returned are rounded to the byte boundary
    greater than the number of bits requested.
    The bits returned are right-justified, and the excess bits (those exceeding
    the requested number of bits) are filled with zeros.
 
PARAMETERS:
    position:
        Required Argument.
        Specifies a ColumnExpression of an integer column or an integer literal
        indicating the starting position of the bit substring to be extracted.
        Notes:
            1. If "position" is negative or out-of-range (meaning that it exceeds
               the size of integer or byte column), an error is returned.
            2. If the argument is NULL, the function returns NULL.
        Format of a ColumnExpression of a column: '<dataframe>.<dataframe_column>'.
        Types: ColumnExpression, int
 
    num_bits:
        Required Argument.
        Specifies a ColumnExpression of an integer column or an integer literal
        indicating the length of the bit substring to be extracted. This
        specifies the number of bits for the function to return.
        Notes:
            1. If "num_bits" is negative, or is greater than the number of bits
               remaining after the starting position is taken into account, an error
               is returned.
            2. If the argument is NULL, the function returns NULL.
        Format of a ColumnExpression of a column: '<dataframe>.<dataframe_column>'.
        Types: ColumnExpression, int
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe", "bytes_table")
 
    # Create a DataFrame on 'bytes_table' table.
    >>> df = DataFrame("bytes_table")
    >>> print(df)
           byte_col      varbyte_col             blob_col
    id_col
    2         b'61'  b'616263643132'  b'6162636431323233'
    1         b'62'      b'62717765'  b'3331363136323633'
    0         b'63'      b'627A7863'  b'3330363136323633'
 
    # Example1: Requests that 3 bits be returned starting at the third bit
    #           from values in "varbyte_col" column and pass it as input to
    #           DataFrame.assign().
    >>> res_df = df.assign(col= df.varbyte_col.subbitstr(2, 3))
    >>> print(res_df)
           byte_col      varbyte_col             blob_col  col
    id_col
    2         b'61'  b'616263643132'  b'6162636431323233'  b'4'
    1         b'62'      b'62717765'  b'3331363136323633'  b'1'
    0         b'63'      b'627A7863'  b'3330363136323633'  b'0'