Practice / aggregations

Distinct Buyers

easy

At The Daily Grind, a store's regulars matter more than its raw order count.

You have the orders DataFrame:

Your task: return each store and a column buyers — the number of distinct customer_ids that ordered there.

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

ordersinput DataFrame

Schema
columntype
order_idlong
storestring
customer_idlong
Sample rows
order_idstorecustomer_id
1Downtown100
2Downtown100
3Downtown101
4Pier200
Expected output shape
storebuyers· 2 rows
Hint

groupBy("store") then agg(F.countDistinct("customer_id").alias("buyers")). You want unique customers, not the number of orders.

Lesson refresher

This problem builds on Aggregations & groupBy (~7 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.