Teradata Package for Python Function Reference - Pivot - 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.Pivot = class Pivot(builtins.object)
     Methods defined here:
__init__(self, data=None, partition_columns=None, target_columns=None, pivot_column=None, pivot_keys=None, numeric_pivotkey=False, num_rows=None, data_sequence_column=None, data_partition_column=None, data_order_column=None)
DESCRIPTION:
    The Pivot function pivots data that is stored in rows into columns.
    It outputs a teradataml DataFrame whose columns are based on the
    individual values from an input teradataml DataFrame column. The schema
    of the output teradataml DataFrame depends on the arguments of the
    function. The function handles missing or NULL values automatically.
 
 
PARAMETERS:
    data:
        Required Argument.
        The teradataml DataFrame containing the data to be pivoted.
 
    data_partition_column:
        Required Argument.
        Specifies Partition By columns for data.
        Values to this argument can be provided as list, if multiple columns
        are used for partition.
        Types: str OR list of Strings (str)
 
    data_order_column:
        Optional Argument.
        Specifies Order By columns for data.
        Values to this argument can be provided as list, if multiple columns
        are used for ordering.
        Types: str OR list of Strings (str)
 
    partition_columns:
        Required Argument.
        Specifies the same columns as the data_partition_column clause (in
        any order).
        Types: str OR list of Strings (str)
 
    target_columns:
        Required Argument.
        Specifies the names of the input columns that contain the values
        to pivot.
        Types: str OR list of Strings (str)
 
    pivot_column:
        Optional Argument.
        Specifies the name of the column that contains the pivot keys.
        If the pivot_column argument contains numeric values, then the
        function casts them to VARCHAR. If you omit the num_rows
        argument, then you must specify this argument.
        Note: If you specify the pivot_column argument, then you must
              order the input data; otherwise, the output teradataml DataFrame
              column content is non-deterministic.
        Types: str
 
    pivot_keys:
        Optional Argument.
        If you specify the pivot_column argument, then this argument
        specifies the names of the pivot keys. Do not use this argument
        without the pivot_column argument. If pivot_column contains a value
        that is not specified as a pivot_keys, then the function ignores the
        row containing that value. pivot_keys is required when pivot_column
        is used.
        Types: str OR list of Strings (str)
 
    numeric_pivotkey:
        Optional Argument.
        Indicates whether the pivot key values are numeric values.
        Default Value: False
        Types: bool
 
    num_rows:
        Optional Argument.
        Specifies the maximum number of rows in any partition. If a
        partition has fewer than num_rows rows, then the function adds
        NULL values; if a partition has more than num_rows rows, then
        the function omits the extra rows. If you omit this argument,
        then you must specify the pivot_column argument.
        Note: With this argument, the data_order_column is optional. If
              omitted, the order of values can vary. The function adds NULL
              values at the end.
        Types: int
 
    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 Pivot.
    Output teradataml DataFrames can be accessed using attribute
    references, such as PivotObj.<attribute_name>.
    Output teradataml DataFrame attribute name is:
        result
 
 
RAISES:
    TeradataMlException
 
 
EXAMPLES:
    # Load example data.
    load_example_data('Pivot', "pivot_input")
 
    # Create teradataml DataFrame objects.
    pivot_input = DataFrame.from_table("pivot_input")
 
    # Example 1 - This example specifies the pivot_column argument and
    # with the pivot_keys argument, which specifies the values from the
    # pivot_column to use as pivot keys. Because pivot_keys does not
    # include 'dewpoint', the function ignores rows that include 'dewpoint'.
    pivot_out1 = Pivot(data=pivot_input,
                data_partition_column=['sn','city','week'],
                partition_columns=['sn','city','week'],
                target_columns='value1',
                pivot_column='attribute',
                pivot_keys=['temp','pressure'],
                numeric_pivotkey=False,
                data_sequence_column='sn')
 
    # Print the result.
    print(pivot_out1)
 
    # Example 2 - Specify the num.rows argument instead of specifying
    # the pivot.column argument.
    pivot_out2 = Pivot(data=pivot_input,
                data_partition_column=['sn','city','week'],
                partition_columns=['sn','city','week'],
                target_columns='value1',
                num_rows=3,
                numeric_pivotkey=False)
 
    # Print the result.
    print(pivot_out2.result)
__repr__(self)
Returns the string representation for a Pivot 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.