Practice / aggregations

Basket Contents

medium

Waveform's merch store wants to see what each shopper is holding.

You have the cart DataFrame:

Your task: return each user_id and a column items — the distinct products in that user's cart, as an alphabetically sorted list.

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

cartinput DataFrame

Schema
columntype
user_idlong
itemstring
Sample rows
user_iditem
1Pen
1Pen
1Notebook
2Eraser
Expected output shape
user_iditems· 2 rows
Hint

F.collect_set("item") gathers the distinct items per group. Wrap it in F.sort_array(...) so the list comes back in a stable alphabetical order.

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.