Two files are involved: datasets/csv/orders.csv (one row per order) and
datasets/csv/users.csv (one row per customer). Join them and report how much
revenue every country produced.
paths['orders'] and
paths['users'].order_status == 'Completed'.user_id and take the country of the customer.total_amount per country and round the result to two decimals.revenue descending, then by country ascending.country, revenue.File questions receive the paths as a third argument:
from pyspark.sql import functions as F
def solve(spark, dfs, paths):
orders = spark.read.csv(paths['orders'], header=True, inferSchema=True)
users = spark.read.csv(paths['users'], header=True, inferSchema=True)
# TODO: join, aggregate and sort
return orders
The same data is also preloaded as dfs['orders'] and dfs['users'] if you prefer
to skip the file reads.
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'].
orders]users]Column names and order must match. Sort order is specified in the question.