Practice / joins

Spend by Name

medium

The Daily Grind wants total spend per customer, labelled by name rather than id.

You have two DataFrames:

orders

customers

Your task: join orders to customers on customer_id, then return each name and their total_spend (the sum of amount).

Assign your answer DataFrame to result. Row order doesn't matter.

ordersinput DataFrame

Schema
columntype
order_idlong
customer_idlong
amountdouble
Sample rows
order_idcustomer_idamount
11005
21007
31014

customersinput DataFrame

Schema
columntype
customer_idlong
namestring
Sample rows
customer_idname
100Priya
101Sam
Expected output shape
nametotal_spend· 2 rows
Hint

Join first, then aggregate: orders.join(customers, on="customer_id", how="inner").groupBy("name").agg(F.sum("amount").alias("total_spend")).

Lesson refresher

This problem builds on Joins (~8 min). Pop it open in a new tab if you want a quick recap.

Loading editor…
Hit Run to execute your code and see the output here.