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

 
Functions
       
Sessionize(data=None, time_column=None, time_out=None, click_lag=None, emit_null=False, **generic_arguments)
DESCRIPTION:
    Sessionize() function maps each click in a session to a unique session identifier.
 
 
PARAMETERS:
    data:
        Required Argument.
        Specifies the input teradataml DataFrame.
        Types: teradataml DataFrame
 
    time_column:
        Required Argument.
        Specifies the name of the input column that contains the click
        times.
        Note: The "time_column" must also be an "order_column".
        Types: str
 
    time_out:
        Required Argument.
        Specifies the number of seconds at which the session times out. If
        "time_out" seconds elapse after a click, then the next click
        starts a new session.
        Types: float
 
    click_lag:
        Optional Argument.
        Specifies the minimum number of seconds between clicks for the
        session user to be considered human. If clicks are more frequent,
        indicating that the user is a bot, the function ignores the session.
        The "click_lag" must be less than "time_out".
        Types: float
 
    emit_null:
        Optional Argument.
        Specifies whether to output rows that have NULL values in their
        session id and rapid fire columns, even if their timestamp_column has
        a NULL value.
        Default Value: False
        Types: bool
 
    **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 Sessionize.
    Output teradataml DataFrames can be accessed using attribute
    references, such as SessionizeObj.<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("sessionize", ["sessionize_table"])
 
    # Create teradataml DataFrame object.
    sessionize_data = DataFrame.from_table("sessionize_table")
 
    # Check the list of available analytic functions.
    display_analytic_functions()
 
    # Example 1: Mapping each click in a session to a unique session identifier.
    #            by partition column 'partition_id' and order column 'clicktime'.
    obj = teradataml.Sessionize(data=sessionize_data,
                                data_partition_column='partition_id',
                                data_order_column='clicktime',
                                time_column='clicktime',
                                time_out=60.0,
                                click_lag=0.2)
 
    # Print the result DataFrame.
    print(obj.result)