pandas_exercises icon indicating copy to clipboard operation
pandas_exercises copied to clipboard

Fix: Remove extra "order_id" sum and make output clean for "Most Popular Item".

Open IVDOT80 opened this issue 1 month ago • 0 comments

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)
image

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)
image

IVDOT80 avatar Nov 02 '25 12:11 IVDOT80