Teradata Package for Python Function Reference | 17.10 - BincodeTransform - 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

Product
Teradata Package for Python
Release Number
17.10
Published
April 2022
Language
English (United States)
Last Update
2022-08-19
lifecycle
previous
Product Category
Teradata Vantage
 
 
BincodeTransform

 
Functions
       
BincodeTransform(data=None, object=None, accumulate=None, **generic_arguments)
DESCRIPTION:
    The BincodeTransform() function is used to convert the continuous numeric data to
    categorical data. The BincodeTransform() function takes the output of BincodeFit()
    function to apply the transform on input DataFrame.
    BincodeTransform() function takes two DataFrames as input:
        1. Input dataframe which contains numeric data to be converted to categorical
           data.
        2. Output of BincodeFit() function which contains the binning data.
 
PARAMETERS:
    data:
        Required Argument.
        Specifies the input teradataml DataFrame.
        Types: teradataml DataFrame
 
    object:
        Required Argument.
        Specifies the teradataml DataFrame containing the binning parameters
        generated by BincodeFit() function or the instance of BincodeFit.
        Types: teradataml DataFrame or BincodeFit
 
    accumulate:
        Optional Argument.
        Specifies the name(s) of input teradataml DataFrame column(s) to copy to the
        output. By default, the function copies no input teradataml
        DataFrame columns to the output table.
        Types: str OR list of Strings (str)
 
    **generic_arguments:
        Specifies the generic keyword arguments SQLE functions accept.
        Below are the generic keyword arguments:
            persist:
                Optional Argument.
                Specifies whether to persist the results of the function in table or
                not. When set to True, results are persisted in table; otherwise,
                results are garbage collected at the end of the session.
                Default Value: False
                Types: boolean
 
            volatile:
                Optional Argument.
                Specifies whether to put the results of the function in volatile table
                or not. When set to True, results are stored in volatile table,
                otherwise not.
                Default Value: False
                Types: boolean
 
            Function allows the user to partition, hash, order or local order the input
            data. These generic arguments are available for each argument that accepts
            teradataml DataFrame as input and can be accessed as:
                * "<input_data_arg_name>_partition_column" accepts str or list of str (Strings)
                * "<input_data_arg_name>_hash_column" accepts str or list of str (Strings)
                * "<input_data_arg_name>_order_column" accepts str or list of str (Strings)
                * "local_order_<input_data_arg_name>" accepts boolean
            Note:
                These generic arguments are supported by teradataml if the underlying
                SQLE Engine function supports, else an exception is raised.
 
RETURNS:
    Instance of BincodeTransform.
    Output teradataml DataFrames can be accessed using attribute
    references, such as BincodeTransformObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
EXAMPLES:
    # Notes:
    #    1. Get the connection to Vantage, before importing the function in user space.
    #    2. User can import the function, if it is available on the Vantage user is connected to.
    #    3. To check the list of analytic functions available on the Vantage user connected to,
    #       use "display_analytic_functions()"
 
    # Load the example data.
    load_example_data("teradataml", ["titanic", "bin_fit_ip"])
 
    # Create teradataml DataFrame objects.
    titanic_data = DataFrame.from_table("titanic")
    bin_fit_ip = DataFrame.from_table("bin_fit_ip")
 
    # Check the list of available analytic functions.
    display_analytic_functions()
 
    # Import functions BincodeFit and BincodeTransform.
    from teradataml import BincodeFit, BincodeTransform
 
    # Example 1: Transform the data using BincodeFit object with Variable-Width.
    # Create BincodeFit object.
    bin_code_1 = BincodeFit(data=titanic_data,
                            fit_data=bin_fit_ip,
                            fit_data_order_column = ['minVal', 'maxVal'],
                            target_columns='age',
                            minvalue_column='minVal',
                            maxvalue_column='maxVal',
                            label_column='label',
                            method_type='Variable-Width',
                            label_prefix='label_prefix'
                           )
 
    # Run BincodeTransform.
    obj = BincodeTransform(data=titanic_data,
                           object=bin_code_1.output,
                           object_order_column="TD_MinValue_BINFIT",
                           accumulate=['PASSENGER', 'ticket']
                          )
 
    # Print the result DataFrame.
    print(obj.result)
 
    # Example 2: Transform the data using BincodeFit object with Equal-Width.
    # Create BincodeFit object.
    bin_code_2 = BincodeFit(data=titanic_data,
                            target_columns='age',
                            method_type='Equal-Width',
                            nbins=2,
                            label_prefix='label_prefix'
                           )
 
    # Run BincodeTransform.
    obj = BincodeTransform(data=titanic_data,
                           object=bin_code_2.output,
                           accumulate=['PASSENGER', 'ticket']
                          )
 
    # Print the result DataFrame.
    print(obj.result)