Teradata Package for Python Function Reference - Unpivot - 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.00
Published
November 2021
Language
English (United States)
Last Update
2021-11-19
lifecycle
previous
Product Category
Teradata Vantage

 
teradataml.analytics.mle.Unpivot = class Unpivot(builtins.object)
     Methods defined here:
__init__(self, data=None, unpivot=None, input_types=False, attribute_column='attribute', value_column='value_col', accumulate=None, data_sequence_column=None, data_order_column=None)
DESCRIPTION:
    The Unpivot function pivots data that is stored in columns into rows.
    It is the reverse of the Pivot function.
 
PARAMETERS:
    data:
        Required Argument.
        Specifies the teradataml DataFrame containing the data to be pivoted.
 
    data_order_column:
        Optional Argument.
        Specifies Order By columns for data.
        Values to this argument can be provided as a list, if multiple
        columns are used for ordering.
        Types: str OR list of Strings (str)
 
    unpivot:
        Required Argument.
        Specifies the names of the unpivot columns — the input columns to
        unpivot (convert to rows).
        Types: str OR list of Strings (str)
 
    input_types:
        Optional Argument.
        Specifies whether the unpivoted value column, in the output teradataml DataFrame,
        has the same data type as its corresponding unpivot column (if
        possible). For each unpivoted column, the function outputs the values
        in a single VARCHAR column. If you specify "true", the function
        outputs each unpivoted value column in a separate column. If the
        unpivot column has a 'real' data type, the unpivoted value column has
        the data type 'float'; if the unpivot column has an 'integer' data type,
        the unpivoted value column has the data type 'int'; if the unpivot
        column has any other data type, the unpivoted value column has the
        data type 'VARCHAR'.
        Default Value: False
        Types: bool
 
    attribute_column:
        Optional Argument.
        Specifies the name of the unpivoted attribute column in the output
        teradataml DataFrame.
        Default Value: "attribute"
        Types: str
 
    value_column:
        Optional Argument.
        Specifies the name of the unpivoted value column in the output
        teradataml DataFrame.
        Default Value: "value_col"
        Types: str
 
    accumulate:
        Required Argument.
        Specifies the names of input columns, other than unpivot columns,
        to copy to the output teradataml DataFrame. You must specify
        these columns in the same order that they appear in the input
        teradataml DataFrame. No accumulate_column can be an unpivot column.
        Types: str OR list of Strings (str)
 
    data_sequence_column:
        Optional Argument.
        Specifies the list of column(s) that uniquely identifies each row of
        the input argument "data". The argument is used to ensure
        deterministic results for functions which produce results that vary
        from run to run.
        Types: str OR list of Strings (str)
 
RETURNS:
    Instance of Unpivot.
    Output teradataml DataFrames can be accessed using attribute
    references, such as UnpivotObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException
 
 
EXAMPLES:
    # Load example data.
    load_example_data('Unpivot', "unpivot_input")
 
 
    # Create teradataml DataFrame objects.
    unpivot_input = DataFrame.from_table("unpivot_input")
 
    # Example 1 -
    unpivot_out1 = Unpivot(data=unpivot_input,
                          unpivot = ["temp","pressure","dewpoint"],
                          input_types = False,
                          attribute_column = "attribute",
                          value_column = "value_col",
                          accumulate = ["sn","city","week"])
    # Print the result
    print(unpivot_out1.result)
 
    # Example 2 -
    unpivot_out2 = Unpivot(data=unpivot_input,
                          unpivot = ["temp","pressure","dewpoint"],
                          input_types = True,
                          attribute_column = "climate_attributes",
                          value_column = "attributevalue",
                          accumulate = ["sn","city","week"])
    # Print the result
    print(unpivot_out2.result)
 
    # Example 3 -
    unpivot_out3 = Unpivot(data=unpivot_input,
                          unpivot =  ["temp","pressure","dewpoint"],
                          input_types = False,
                          accumulate = ["sn","city","week"])
    # Print the result
    print(unpivot_out3.result)
__repr__(self)
Returns the string representation for a Unpivot class instance.
get_build_time(self)
Function to return the build time of the algorithm in seconds.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
get_prediction_type(self)
Function to return the Prediction type of the algorithm.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
get_target_column(self)
Function to return the Target Column of the algorithm.
When model object is created using retrieve_model(), then the value returned is
as saved in the Model Catalog.
show_query(self)
Function to return the underlying SQL query.
When model object is created using retrieve_model(), then None is returned.