A chain of shops records how many units of each product every store sold last week. You want each store's best sellers, listed store by store.
Write top_products_per_store(df, n).
df has the columns store (text), product (text) and units (whole number). n is a whole number, at least 1.
Put the rows in this order:
store, A to Z;units, largest first;units, by product, A to Z.Then keep the first n rows of each store in that order. A store with fewer than n rows keeps all of them.
Return a new DataFrame with the columns store, product, units, in the order described above.
df.groupby(...).apply(...) for this task. Recent pandas versions warn when the applied function returns the grouping column, and newer versions leave that column out of the result.