← 返回 uber 的题目列表Pandas GroupBy Aggregation on Multiple DataFrames
类型:online_judge
Problem: GroupBy Aggregation Across Three DataFrames (Pandas)
You are given three pandas.DataFrames (df1, df2, df3) containing Uber Eats order/item related data. You need to join/merge them into an analysis-ready table and use groupby plus aggregation functions to compute metrics.
Requirements
Merge the three DataFrames using appropriate keys (state which keys you used).
Compute the average sales for each category.
Return a DataFrame/table with:
columns: category, avg_sales
sorted by avg_sales in descending order.
Notes
If an order can have multiple item rows, clarify the definition of “sales” you are using (item-level vs order-level).
Only the core analysis logic is required.
Scale assumptions
Up to 10^6 rows per DataFrame.
Consider time/space efficiency.
Example (one possible schema)
df1(order_id, item_id, category, item_sales)
df2(order_id, user_id, is_completed)
df3(item_id, merchant_id)
Compute the mean of item_sales per category.
Example
Input
df1: [(1,'a','alcohol',10),(1,'b','food',20),(2,'c','alcohol',30)]
df2: [(1,101,1),(2,102,0)]
df3: [('a',900),('b',901),('c',902)]
Output
category avg_sales
food 20.0
alcohol 10.0 # if filtering to completed orders only (order_id=1)