Shipping Cost Share

Medium
Arithmetic

Shipping Cost Share

The orders table contains subtotals and shipping fees.

Return order_id, shipping_pct, where shipping_pct is shipping as a percentage of the total order value (subtotal + shipping_fee), rounded to 2 decimal places. Sort by order_id 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.orders6 rows
order_id (int)subtotal (double)shipping_fee (double)
1405
212.53.5
399.990
47.252.75
515012.5
623.44.6

Return these columns

order_id(int)
shipping_pct(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.