Top Two Categories by Revenue

Easy
Aggregation
Ranking

Top Two Categories by Revenue

The sales table contains sale amounts by category.

Return the two categories with the highest total revenue as category, revenue. Sort by revenue descending, then category ascending.

Browser Engine: Evaluates PySpark DataFrame & SQL logic locally in Pyodide WebAssembly.

Input data

1 DataFrame

These DataFrames are passed to solve(spark, dfs). Access one with dfs['name'].

df.sales7 rows
sale_id (int)category (string)amount (double)
1Books20
2Games55
3Books30
4Home40
5Games10
6Home5
7Books5

Return these columns

category(string)
revenue(double)

Column names and order must match. Sort order is specified in the question.

Browser engine
Loading Python editor…
Click Run to try the sample cases, or Submit to check the hidden cases. First run caches the browser Python engine (~8–15s once); all code stays on your device.