← 返回 amazon 的题目列表Filter Top Daily Sales Rows by Category
类型:online_judge
Given a table containing product sales information including date, category, and sales amount. You need to filter and classify the data by each day and category, and select the top 5 sales records each day for each category.
Input: A dataframe containing columns Date, Category, Sales.
Output: A dataframe containing the top 5 daily sales records for each category.
Constraints:
Minimize time complexity as much as possible.
Example:
Input:
Date Category Sales
2023-01-01 A 100
2023-01-01 B 200
2023-01-01 A 150
2023-01-01 B 250
2023-01-01 A 50
2023-01-01 B 300
2023-01-01 A 450
2023-01-02 A 200
2023-01-02 B 250
2023-01-02 A 100
Output:
Date Category Sales
2023-01-01 A 450
2023-01-01 A 150
2023-01-01 A 100
2023-01-01 B 300
2023-01-01 B 250
2023-01-02 A 200
2023-01-02 B 250
2023-01-02 A 100
Data Scale:
The number of records in the table does not exceed 10^6.
Example
Input
Date,Category,Sales
2023-01-01,A,100
2023-01-01,B,200
2023-01-01,A,150
2023-01-01,B,250
2023-01-01,A,50
2023-01-01,B,300
2023-01-01,A,450
2023-01-02,A,200
2023-01-02,B,250
2023-01-02,A,100