Analyze Sales Data to Find Top Performers by Region
PYSPARK coding challenge · Difficulty: hard · +200 XP
Given a sales_data table that contains information about sales transactions across various regions, your task is to identify the top 2 salespersons per region based on the total sales amount. The table might contain duplicate transactions due to report generation errors. You need to ensure that duplicates are handled correctly and that only the top 2 salespersons by total sales amount are returned for each region.
Example input
`
sales_data DataFrame:
region | salesperson | sales_amount
North | Alice | 300 ← duplicate
North | Alice | 300 ← duplicate
North | Bob | 500
North | Charlie | 200
South | David | 700
South | Eve | 600 ← duplicate
South | Eve | 600 ← duplicate
South | Frank | 300
`
Expected output
`
+------+-----------+-----------+
|region|salesperson|total_sales|
+------+-----------+-----------+
|North |Bob |500 | |North |Alice |300 | |South |David |700 | |South |Eve |600 |
+------+-----------+-----------+
`