"Top N per group" is one of the most common real queries in analytics, and the naive implementation — groupby(...).apply(lambda g: g.nlargest(n)) — is both the slow answer and, once two rows tie, an answer that is not even deterministic.
Write top_n_per_group(df, n). Given a DataFrame with group, id and score columns, return the top n rows per group by score descending.
Ties in score are broken by id ascending, always — two runs on the same input must return the identical rows in the identical order. A group with fewer than n rows returns all of them; nothing is padded and nothing raises.
Output columns are group, id, score, sorted by group ascending, then by rank within the group (highest score first, ties broken by id ascending).
Build the architecture on a canvas: place the components, configure them, connect them into a data flow, and write a short reason for each one. The AI reviewer grades your design against a rubric written specifically for this problem.
Minimum 5 components · needs a wide desktop screen