agg() Method

Teradata® Python Package User Guide

Teradata Vantage
Teradata Python Package
User Guide

Use the agg() method to apply aggregate methods to columns of a DataFrame.

The method takes as a method name, a list of method names or a dictionary of column name to method names.

Example: Use dictionary of column names to lists of method names

>>> df.agg({'employee_no' : ['min', 'sum'], 'first_name' : ['min', 'mean']})
      min_employee_no sum_employee_no min_first_name
    0             100             313           abcd

Example: Apply the methods min and sum to all the columns

>>> df.agg(['min', 'sum'])
      min_employee_no sum_employee_no min_first_name min_marks sum_marks min_dob min_joined_date
    0             100             313           abcd      None      None    None      1902-05-12

Example: Apply the method mean to all the columns

>>> df.agg('mean')
       mean_employee_no mean_marks mean_dob mean_joined_date
    0        104.333333       None     None       1960-05-11

Example: Apply the method mean and unique to selected columns

>>> df1 =['employee_no', 'first_name', 'joined_date'])
>>> df1.agg(['mean', 'unique'])
       mean_employee_no unique_employee_no unique_first_name mean_joined_date unique_joined_date
    0        104.333333                  3                 2       1960-05-11                  2

Example: Apply the method percentile to all the columns

>>> df.agg('percentile')
      percentile_employee_no percentile_marks
    0                    101             None