pandas_exercises
pandas_exercises copied to clipboard
Fix: Remove extra "order_id" sum and make output clean for "Most Popular Item".
Description
Problem:
The code for finding the most popular item used in the solution:
c = chipo.groupby('item_name')
c = c.sum()
c = c.sort_values(['quantity'], ascending=False)
c.head(1)
This caused problems:
- It added all columns, including 'order_id'. Even though the expected answer shows an 'order_id' column, it only displays the sum of order Ids, which has no real meaning.
- The result doesn't match the expected output in the solution.
Fixed:
The code now only uses 'item_name' and 'quantity' before grouping and summing:
c = chipo[['item_name','quantity']].groupby('item_name')
c = c.sum()
c = c.sort_values(['quantity'], ascending=False)
c.head(1)