The file datasets/csv/order_items.csv holds one row per item of an order. A line
is worth quantity * unit_price * (1 - discount / 100) - the discount is a
percentage. Which products bring in the most money?
paths['order_items'].line_revenue with quantity * unit_price * (1 - discount / 100).line_revenue per product_id and round the result to two decimals.revenue descending, then by product_id ascending.product_id, revenue.File questions receive the path as a third argument:
from pyspark.sql import functions as F
def solve(spark, dfs, paths):
items = spark.read.csv(paths['order_items'], header=True, inferSchema=True)
# TODO: add the line revenue, aggregate and sort
return items
The same data is also preloaded as dfs['order_items'] if you prefer to skip the file read.
This question runs in your browser - no sign-in needed. Press Run for the sample data and Submit for the hidden data.
These files are loaded into this browser when you run. Their paths are handed to your code as the third argument: solve(spark, dfs, paths). Read one with spark.read.csv(paths['users'], header=True), or skip the read and use dfs['users'].
order_items]Column names and order must match. Sort order is specified in the question.