Arrange the following functions of GROUP BY according to its working strategy:
(A) Combine the results
(B) Split the data
(C) Create the input DataFrame
(D) Apply the function
Arrange the following functions of GROUP BY according to its working strategy:
(A) Combine the results
(B) Split the data
(C) Create the input DataFrame
(D) Apply the function
Solution
GROUP BY in pandas follows the split-apply-combine strategy. The input DataFrame must exist first, then it is split into groups, the function is applied to each group, and the results are combined.
(C) Create the input DataFrame
(B) Split the data into groups by the key
(D) Apply the function (sum, mean, count, etc.) to each group
(A) Combine the results into a new DataFrame or Series
Option 2: combining cannot come before applying, because there are no per-group results to combine until the function has run.
Related questions:
2026: 29 May Shift 1
2025: 14 May Shift 1