Teradata Package for Python Function Reference on VantageCloud Lake - ColumnTransformer - 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
 
 
ColumnTransformer

 
Functions
       
ColumnTransformer(input_data=None, bincode_fit_data=None, function_fit_data=None, nonlinearcombine_fit_data=None, onehotencoding_fit_data=None, ordinalencoding_fit_data=None, outlierfilter_fit_data=None, polynomialfeatures_fit_data=None, rownormalize_fit_data=None, scale_fit_data=None, simpleimpute_fit_data=None, fillrowid_column_name=None, **generic_arguments)
DESCRIPTION:
    The ColumnTransformer() function transforms the input data columns in a single operation.Provide only
    the FIT dataframes generated by the Fit analytic functions, and the function runs all transformations
    that user require in a single operation.
    The function performs the following transformations:
            * Scale Transform
            * Bincode Transform
            * Function Transform
            * NonLinearCombine Transform
            * OutlierFilter Transform
            * PolynomialFeatures Transform
            * RowNormalize Transform
            * OrdinalEncoding Transform
            * OneHotEncoding Transform
            * SimpleImpute Transform
    User must create the FIT dataframe before using the function and must be provided in the same order
    as in the training data sequence to transform the dataset. The FIT dataframe can have maximum of
    128 columns.
    Note:
        * ColumnTransformer() function works only with python 3.6 and above.
 
 
PARAMETERS:
    input_data:
        Required Argument.
        Specifies the teradataml DataFrame that contains input data.
        Types: teradataml DataFrame
 
    bincode_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the BincodeFit() function.
        Types: teradataml DataFrame
 
    function_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the Fit() function.
        Types: teradataml DataFrame
 
    nonlinearcombine_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the NonLinearCombineFit() function.
        One can pass multiple NonLinearCombineFit() function's output using argument names
        as nonlinearcombine_fit_data1, nonlinearcombine_fit_data2 and so on.
        Notes:
                * Function considers the arguments which are in sequence and ignores the arguments
                which are out of sequence.
                Example - If arguments are nonlinearcombine_fit_data, nonlinearcombine_fit_data1,
                nonlinearcombine_fit_data2, nonlinearcombine_fit_data4, the function considers only
                nonlinearcombine_fit_data, nonlinearcombine_fit_data1 and nonlinearcombine_fit_data2
                for processing and ignores nonlinearcombine_fit_data4 since it is out of sequence.
                * Argument sequence starts from "nonlinearcombine_fit_data", followed by
                "nonlinearcombine_fit_data1", "nonlinearcombine_fit_data2", so on..
        Types: teradataml DataFrame
 
    onehotencoding_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the OneHotEncodingFit() function.
        Types: teradataml DataFrame
 
    ordinalencoding_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the OrdinalEncodingFit() function.
        Types: teradataml DataFrame
 
    outlierfilter_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the OutlierFilterFit() function.
        Types: teradataml DataFrame
 
    polynomialfeatures_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the PolynomialFeaturesFit() function.
        Types: teradataml DataFrame
 
    rownormalize_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the RowNormalizeFit() function.
        Types: teradataml DataFrame
 
    scale_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the ScaleFit() function.
        Types: teradataml DataFrame
 
    simpleimpute_fit_data:
        Optional Argument.
        Specifies the teradataml DataFrame generated by the SimpleImputeFit() function.
        Types: teradataml DataFrame
 
    fillrowid_column_name:
        Optional Argument.
        Specifies the name for the output column in which unique identifiers for each row are
        populated.
        Types: 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 a table or not. When set to True,
                results are persisted in a table; otherwise,
                results are garbage collected at the end of the
                session.
                Default Value: False
                Types: bool
 
            volatile:
                Optional Argument.
                Specifies whether to put the results of the
                function in a volatile table or not. When set to
                True, results are stored in a volatile table,
                otherwise not.
                Default Value: False
                Types: bool
 
        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 ColumnTransformer.
    Output teradataml DataFrames can be accessed using attribute
    references, such as ColumnTransformerObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException, TypeError, ValueError
 
 
EXAMPLES:
    # Notes:
    #     1. Get the connection to Vantage to execute the function.
    #     2. One must import the required functions mentioned in
    #        the example from teradataml.
    #     3. Function will raise error if not supported on the Vantage
    #        user is connected to.
 
    # Load the example data.
    load_example_data("teradataml", ["titanic"])
 
    # Create teradataml DataFrame objects.
    titanic = DataFrame.from_table("titanic")
 
    # Check the list of available analytic functions.
    display_analytic_functions()
 
    # Example 1: Perform Bincode transformation and OneHotEncoding transformation using fit functions and
    #             ColumnTransformer() function.
    bin_code = BincodeFit(data=titanic,
                          target_columns='age',
                          method_type='Equal-Width',
                          nbins=2,
                          label_prefix='label_prefix')
 
    one_hot_encoding = OneHotEncodingFit(data=titanic,
                                         is_input_dense=True,
                                         target_column="sex",
                                         categorical_values=["male", "female"],
                                         other_column="other")
 
    ColumnTransformer_out = ColumnTransformer(fillrowid_column_name="output_value",
                                              input_data=titanic,
                                              bincode_fit_data=bin_code.output,
                                              onehotencoding_fit_data=one_hot_encoding.result)
 
    # Print the result DataFrame.
    print(ColumnTransformer_out.result)
 
    # Example 2: Perform multiple NonLinearCombineFit transformation using fit function and
    #            ColumnTransformer() function.
    # Create multiple NonLinearCombineFit objects and pass those to ColumnTransformer.
    NonLinearCombineFit_out1 = NonLinearCombineFit(data = titanic,
                                                   target_columns = ["sibsp", "parch"],
                                                   formula = "Y=(X0+X1+1)",
                                                   result_column = "total_cost")
 
    NonLinearCombineFit_out2 = NonLinearCombineFit(data = titanic,
                                                   target_columns = [ "fare"],
                                                   formula = "Y=(X0+1)",
                                                   result_column = "total_fare_cost2")
 
    NonLinearCombineFit_out3 = NonLinearCombineFit(data = titanic,
                                                   target_columns = [ "fare"],
                                                   formula = "Y=(X0+3)",
                                                   result_column = "total_fare_cost3")
 
    ColumnTransformer_out2 = ColumnTransformer(input_data=titanic,
                                               nonlinearcombine_fit_data=NonLinearCombineFit_out1.result,
                                               nonlinearcombine_fit_data_order_column=['parch'],
                                               nonlinearcombine_fit_data1=NonLinearCombineFit_out2.result,
                                               nonlinearcombine_fit_data1_order_column=['fare'],
                                               nonlinearcombine_fit_data2=NonLinearCombineFit_out3.result)
 
    # Print the result DataFrame.
    print(ColumnTransformer_out2.result)
 
    # Example 3: Perform BincodeFit transformation along with OrdinalEncodingFit and
    #            OneHotEncodingFit transformation using fit functions and ColumnTransformer()
    #            function.
    # Create BincodeFit object along with OrdinalEncodingFit and OneHotEncodingFit
    # objects, and pass those to ColumnTransformer.
    bin_code = BincodeFit(data=titanic,
                          target_columns='age',
                          method_type='Equal-Width',
                          nbins=2,
                          label_prefix='label_prefix')
 
    one_hot_encoding = OneHotEncodingFit(data=titanic,
                                          is_input_dense=True,
                                          target_column="embarked",
                                          categorical_values=["c", "s"],
                                          other_column="other")
 
    ordinal_encodingfit = OrdinalEncodingFit(target_column='sex', data=titanic)
 
    ColumnTransformer_out3 = ColumnTransformer(fillrowid_column_name="output_value",
                                               input_data=titanic,
                                               bincode_fit_data=bin_code.output,
                                               onehotencoding_fit_data=one_hot_encoding.result,
                                               ordinalencoding_fit_data=ordinal_encodingfit.result)
 
    # Print the result DataFrame.
    print(ColumnTransformer_out3.result)