Teradata Package for Python Function Reference on VantageCloud Lake | 17.20 - getbit - 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
17.20
Publication Date
November 2022
Content Type
Programming Reference
Publication ID
B700-4500-112K
ft:locale
en-US
ft:lastEdition
2024-02-21
ft:sourceId
FTML
dita:id
TeradataPython_FxRef_Lake_1720
Product Category
Teradata Vantage
teradataml.dataframe.sql.DataFrameColumn.getbit = getbit(bit_mask)
DESCRIPTION:
    Function returns the bit specified by "bit_mask" from the integer or byte value
    in column and returns either 0 or 1 to indicate the value of that bit.
 
PARAMETERS:
    bit_mask:
        Required Argument.
        Specifies a ColumnExpression of an integer column or an integer literal.
        Notes:
            1. The range of input values can vary from 0 (bit 0 is the least significant
               bit) to the (sizeof(integer or byte value in column) - 1).
            2. If "bit_mask" is negative or out-of-range (meaning that it exceeds the size
               of integer or byte value in column), an error is returned.
            3. If the argument is NULL, the function returns NULL.
        Format of a ColumnExpression of a column: '<dataframe>.<dataframe_column>'.
        Types: ColumnExpression, int
 
RAISES:
    TypeError, ValueError, TeradataMlException
 
RETURNS:
    DataFrameColumn
 
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: Retrieves the fourth bit from the values in "varbyte_col" column
    #           and pass it as input to DataFrame.assign().
    >>> res_df = df.assign(col= df.varbyte_col.getbit(3))
    >>> print(res_df)
           byte_col      varbyte_col             blob_col  col
    id_col
    2         b'61'  b'616263643132'  b'6162636431323233'    0
    1         b'62'      b'62717765'  b'3331363136323633'    0
    0         b'63'      b'627A7863'  b'3330363136323633'    0