Returning Customer Rate

Medium
Aggregation
Arithmetic

Returning Customer Rate

The orders table contains order rows by customer.

Return one row with returning_customers, total_customers, and returning_rate, where returning customers have more than one order and the rate is a percentage rounded to 2 decimal places.

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.orders10 rows
order_id (int)customer_id (int)
1101
2101
3101
4102
5103
6103
7104
8105
9105
10105

Return these columns

returning_customers(int)
total_customers(int)
returning_rate(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.