Teradata Package for Python Function Reference | 20.00 - groupby - 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 - 20.00

Deployment
VantageCloud
VantageCore
Edition
VMware
Enterprise
IntelliFlex
Product
Teradata Package for Python
Release Number
20.00.00.11
Published
August 2026
ft:locale
en-US
ft:lastEdition
2026-08-13
dita:id
TeradataPython_FxRef_Enterprise_2000
Product Category
Teradata Vantage
teradataml.dataframe.dataframe.DataFrame.groupby = groupby(self, columns_expr, **kwargs)
DESCRIPTION:
    Applies GroupBy to one or more columns of a teradataml Dataframe.
    The result will always behaves like calling groupby with as_index=False
    in pandas.
 
PARAMETERS:
    columns_expr:
        Required Argument.
        Specifies the column name(s) to group by.
        Types: str OR list of Strings (str)
 
    kwargs:
        Optional Argument.
        Specifies keyword arguments.
 
        option:
            Optional Argument.
            Specifies the groupby option.
            Permitted Values: "CUBE", "ROLLUP", None
            Types: str or NoneType
 
        include_grouping_columns:
            Optional Argument.
            Specifies whether to include aggregations on the grouping column(s) or not.
            When set to True, the resultant DataFrame will have the aggregations on the
            columns mentioned in "columns_expr". Otherwise, resultant DataFrame will not have
            aggregations on the columns mentioned in "columns_expr".
            Default Value: False
            Types: bool
 
NOTES:
    * Users can still apply teradataml DataFrame methods (filters/sort/etc) on top of the result.
    * Consecutive operations of grouping, i.e., groupby_time(), resample() and groupby() are not permitted.
       An exception will be raised. Following are some cases where exception will be raised as
       "Invalid operation applied, check documentation for correct usage."
            a. df.resample().groupby()
            b. df.resample().resample()
            c. df.resample().groupby_time()
    * This method does not support operations on array columns.
 
RETURNS:
    teradataml DataFrameGroupBy Object
 
RAISES:
    TeradataMlException
 
EXAMPLES:
    # Load the data to run the example.
    >>> load_example_data("dataframe","admissions_train")
 
    # Create a DataFrame on 'admissions_train' table.
    >>> df = DataFrame("admissions_train")
    >>> df
       masters   gpa     stats programming  admitted
    id
    15     yes  4.00  Advanced    Advanced         1
    34     yes  3.85  Advanced    Beginner         0
    13      no  4.00  Advanced      Novice         1
    38     yes  2.65  Advanced    Beginner         1
    5       no  3.44    Novice      Novice         0
    40     yes  3.95    Novice    Beginner         0
    7      yes  2.33    Novice      Novice         1
    22     yes  3.46    Novice    Beginner         0
    26     yes  3.57  Advanced    Advanced         1
    17      no  3.83  Advanced    Advanced         1
 
    # Example 1: Find the minimum value of all valid columns by
    #            grouping the DataFrame with column 'masters'.
    >>> df1 = df.groupby(["masters"])
    >>> df1.min()
      masters min_id  min_gpa min_stats min_programming min_admitted
    0      no      3     1.87  Advanced        Advanced            0
    1     yes      1     1.98  Advanced        Advanced            0
 
    # Example 2: Find the sum of all valid columns by grouping the DataFrame
    #            with columns 'masters' and 'admitted'. Include grouping columns
    #            in aggregate function 'sum'.
    >>> df1 = df.groupby(["masters", "admitted"], include_grouping_columns=True)
    >>> df1.sum()
      masters  admitted  sum_id  sum_gpa  sum_admitted
    0     yes         1     188    34.35            10
    1     yes         0     289    43.36             0
    2      no         0      41     6.44             0
    3      no         1     302    57.52            16
 
    # Example 3: Find the sum of all valid columns by grouping the DataFrame with
    #            columns 'masters' and 'admitted'. Do not include grouping columns
    #            in aggregate function 'sum'.
    >>> df1 = df.groupby(["masters", "admitted"], include_grouping_columns=False)
    >>> df1.sum()
      masters  admitted  sum_id  sum_gpa
    0     yes         0     289    43.36
    1      no         0      41     6.44
    2      no         1     302    57.52
    3     yes         1     188    34.35