Average Rating Excluding Nulls

Easy
Aggregation
Data Cleaning

Average Rating Excluding Nulls

The reviews table contains product ratings, but some ratings are missing.

Return product_id, avg_rating with the average of the non-null ratings, rounded to 2 decimal places. If a product has no ratings, avg_rating should be null. Sort by product_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.reviews8 rows
review_id (int)product_id (int)rating (int)
1105
2104
3113
411null
5124
6122
713null
813null

Return these columns

product_id(int)
avg_rating(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.