Practice / reshaping

The Store-Month Grid

medium

The Daily Grind wants a revenue cross-tab: stores down the side, months across the top.

sales

Your task: produce one row per store with a Jun and a Jul column holding the total amount for that store in that month.

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

salesinput DataFrame

Schema
columntype
storestring
monthstring
amountdouble
Sample rows
storemonthamount
DowntownJun10
DowntownJun5
DowntownJul8
PierJun4
PierJul6
PierJul6
Expected output shape
storeJunJul· 2 rows
Hint

groupBy("store").pivot("month", ["Jun", "Jul"]).agg(F.sum("amount")). Passing the value list to pivot fixes the column order and skips a scan.

Lesson refresher

This problem builds on Reshaping Data (~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.