Teradata Package for Python Function Reference on VantageCloud Lake - cube - 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
20.00.00.08
Published
November 2025
ft:locale
en-US
ft:lastEdition
2025-12-05
dita:id
TeradataPython_FxRef_Lake_2000
Product Category
Teradata Vantage
teradataml.dataframe.dataframe.DataFrame.cube = cube(self, columns, include_grouping_columns=False)
DESCRIPTION:
    cube() function creates a multi-dimensional cube for the DataFrame
    using the specified column(s), and there by running aggregates on
    it to produce the aggregations on different dimensions.
 
 
PARAMETERS:
    columns:
        Required Argument.
        Specifies the name(s) of input teradataml DataFrame column(s).
        Types: str OR list of str(s)
 
    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". Otherwise, resultant DataFrame will not have 
        aggregations on the columns mentioned in "columns".
        Default Value: False
        Types: bool
 
RETURNS:
    teradataml DataFrameGroupBy
 
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 sum of all valid columns by grouping the
    #            DataFrame columns with 'masters' and 'stats'.
    >>> df1 = df.cube(["masters", "stats"]).sum()
    >>> df1
      masters     stats  sum_id  sum_gpa  sum_admitted
    0      no  Beginner       8     3.60             1
    1    None  Advanced     555    84.21            16
    2    None  Beginner      21    18.31             3
    3     yes  Beginner      13    14.71             2
    4    None      None     820   141.67            26
    5     yes  Advanced     366    49.26             7
    6      no      None     343    63.96            16
    7    None    Novice     244    39.15             7
    8      no  Advanced     189    34.95             9
    9     yes    Novice      98    13.74             1
 
    # Example 2: Find the avg of all valid columns by grouping the DataFrame
    #            with columns 'masters' and 'admitted'. Include grouping columns
    #            in aggregate function 'avg'.
    >>> df1 = df.cube(["masters", "admitted"], include_grouping_columns=True).avg()
    >>> df1
      masters  admitted     avg_id   avg_gpa  avg_admitted
    0     yes       NaN  21.681818  3.532273      0.454545
    1    None       1.0  18.846154  3.533462      1.000000
    2      no       NaN  19.055556  3.553333      0.888889
    3     yes       0.0  24.083333  3.613333      0.000000
    4    None       NaN  20.500000  3.541750      0.650000
    5    None       0.0  23.571429  3.557143      0.000000
    6     yes       1.0  18.800000  3.435000      1.000000
    7      no       1.0  18.875000  3.595000      1.000000
    8      no       0.0  20.500000  3.220000      0.000000
 
    # Example 3: Find the avg of all valid columns by grouping the DataFrame with
    #            columns 'masters' and 'admitted'. Do not include grouping columns
    #            in aggregate function 'avg'. 
    >>> df1 = df.cube(["masters", "admitted"], include_grouping_columns=False).avg()
    >>> df1
      masters  admitted     avg_id   avg_gpa
    0      no       0.0  20.500000  3.220000
    1    None       1.0  18.846154  3.533462
    2      no       NaN  19.055556  3.553333
    3     yes       0.0  24.083333  3.613333
    4    None       NaN  20.500000  3.541750
    5    None       0.0  23.571429  3.557143
    6     yes       1.0  18.800000  3.435000
    7     yes       NaN  21.681818  3.532273
    8      no       1.0  18.875000  3.595000