Teradata Package for Python Function Reference on VantageCloud Lake | 17.20 - max - 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
17.20
Publication Date
November 2022
Content Type
Programming Reference
Publication ID
B700-4500-112K
ft:locale
en-US
ft:lastEdition
2024-02-21
ft:sourceId
FTML
dita:id
TeradataPython_FxRef_Lake_1720
Product Category
Teradata Vantage
teradataml.dataframe.window.max = max(distinct=False)
DESCRIPTION:
    Function returns the maximum of values in teradataml DataFrame or
    ColumnExpression over the specified window.
 
PARAMETERS:
    distinct:
        Optional Argument.
        Specifies a flag that decides whether to consider duplicate values in
        a column or not.
        Default Values: False
        Types: bool
 
RETURNS:
    * teradataml DataFrame - When aggregate is executed using window created
      on teradataml DataFrame.
    * ColumnExpression, also known as, teradataml DataFrameColumn - When aggregate is
      executed using window created on ColumnExpression.
 
RAISES:
    RuntimeError - If column does not support the aggregate operation.
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe", "admissions_train")
    >>>
 
    # Create a teradataml DataFrame on 'admissions_train' table.
    >>> admissions_train = DataFrame("admissions_train")
    >>> admissions_train
       masters   gpa     stats programming  admitted
    id
    22     yes  3.46    Novice    Beginner         0
    36      no  3.00  Advanced      Novice         0
    15     yes  4.00  Advanced    Advanced         1
    38     yes  2.65  Advanced    Beginner         1
    5       no  3.44    Novice      Novice         0
    17      no  3.83  Advanced    Advanced         1
    34     yes  3.85  Advanced    Beginner         0
    13      no  4.00  Advanced      Novice         1
    26     yes  3.57  Advanced    Advanced         1
    19     yes  1.98  Advanced    Advanced         0
    >>>
 
    # Example 1: Calculate the maximum of values for the 'gpa' column
    #            in a Rolling window, partitioned over 'programming'.
    # Create a Rolling window on 'gpa'.
    >>> window = admissions_train.gpa.window(partition_columns="programming",
    ...                                      window_start_point=-2,
    ...                                      window_end_point=0)
    >>>
    # Execute max() on the Rolling window and attach it to the teradataml DataFrame.
    # Note: DataFrame.assign() allows combining multiple window aggregate operations
    #       in one single call. In this example, we are executing count() along with
    #       max() window aggregate operations.
    >>> df = admissions_train.assign(max_gpa=window.max(), count_gpa=window.count())
    >>> df
       masters   gpa     stats programming  admitted  count_gpa  max_gpa
    id
    11      no  3.13  Advanced    Advanced         1          3     3.83
    27     yes  3.96  Advanced    Advanced         0          3     3.96
    26     yes  3.57  Advanced    Advanced         1          3     3.96
    6      yes  3.50  Beginner    Advanced         1          3     3.96
    9       no  3.82  Advanced    Advanced         1          3     3.82
    25      no  3.96  Advanced    Advanced         1          3     3.96
    39     yes  3.75  Advanced    Beginner         0          1     3.75
    31     yes  3.50  Advanced    Beginner         1          2     3.75
    29     yes  4.00    Novice    Beginner         0          3     4.00
    21      no  3.87    Novice    Beginner         1          3     4.00
    >>>
 
    # Example 2: Calculate the maximum value of all the valid columns in teradataml
    #            DataFrame, in an Expanding window, partitioned over 'programming',
    #            and order by 'id' in descending order.
    # Create an Expanding window on teradataml DataFrame.
    >>> window = admissions_train.window(partition_columns="masters",
    ...                                  order_columns="id",
    ...                                  sort_ascending=False,
    ...                                  window_start_point=None,
    ...                                  window_end_point=0)
    >>>
    # Execute max() on the Expanding window.
    >>> df = window.max()
    >>> df
       masters   gpa     stats programming  admitted  admitted_max  gpa_max  id_max masters_max programming_max stats_max
    id
    38     yes  2.65  Advanced    Beginner         1             1     3.95      40         yes        Beginner    Novice
    32     yes  3.46  Advanced    Beginner         0             1     3.95      40         yes        Beginner    Novice
    31     yes  3.50  Advanced    Beginner         1             1     3.95      40         yes        Beginner    Novice
    30     yes  3.79  Advanced      Novice         0             1     3.95      40         yes          Novice    Novice
    27     yes  3.96  Advanced    Advanced         0             1     4.00      40         yes          Novice    Novice
    26     yes  3.57  Advanced    Advanced         1             1     4.00      40         yes          Novice    Novice
    37      no  3.52    Novice      Novice         1             1     3.52      37          no          Novice    Novice
    36      no  3.00  Advanced      Novice         0             1     3.52      37          no          Novice    Novice
    35      no  3.68    Novice    Beginner         1             1     3.68      37          no          Novice    Novice
    33      no  3.55    Novice      Novice         1             1     3.68      37          no          Novice    Novice
    >>>
 
    # Example 3: Calculate the maximum value of all the valid columns in
    #            teradataml DataFrame, which are grouped by 'masters' and 'gpa'
    #            in a Contracting window, partitioned over 'masters' and order
    #            by 'masters' with nulls in masters listed last.
    # Perform group_by() operation on teradataml DataFrame.
    >>> group_by_df = admissions_train.groupby(["masters", "gpa"])
    # Create a Contracting window on teradataml DataFrameGroupBy object.
    >>> window = group_by_df.window(partition_columns="masters",
    ...                             order_columns="masters",
    ...                             nulls_first=False,
    ...                             window_start_point=-5,
    ...                             window_end_point=None)
    # Execute max() on the Contracting window.
    >>> window.max()
      masters   gpa  gpa_max masters_max
    0      no  3.71     4.00          no
    1      no  3.52     4.00          no
    2      no  3.68     4.00          no
    3      no  3.83     4.00          no
    4      no  3.55     4.00          no
    5      no  3.96     4.00          no
    6     yes  3.59     3.95         yes
    7     yes  3.95     3.95         yes
    8     yes  3.46     3.95         yes
    9     yes  3.76     3.95         yes
    >>>