Which of the following syntax are correct for data aggregation methods in pandas?
(A) df.aggregate('max')
(B) df.aggregate('sort')
(C) df['maths'].aggregate(['max', 'min'])
(D) df[['maths', 'science']].aggregate('sum', axis=1)
Which of the following syntax are correct for data aggregation methods in pandas?
(A) df.aggregate('max')
(B) df.aggregate('sort')
(C) df['maths'].aggregate(['max', 'min'])
(D) df[['maths', 'science']].aggregate('sum', axis=1)
Solution
(A), (C) and (D) are valid. aggregate() (or agg()) accepts a function name as a string, a function, or a list of functions, and the function must reduce data to a single value.
(A) df.aggregate('max') gives the maximum of each column.
(C) df['maths'].aggregate(['max', 'min']) gives both the maximum and minimum of the Series.
(D) df[['maths', 'science']].aggregate('sum', axis=1) gives the row-wise sum of the two columns.
(B): 'sort' is not an aggregation function. It reorders data instead of reducing it, and pandas raises an error saying 'sort' is not a valid function for a DataFrame.
Related questions:
2026: 19 May Shift 1
2025: 15 May Shift 2
2026: 18 May Shift 2
2025: 27 May Shift 2
2026: 29 May Shift 1