Skip to content
Advertisement

pandas sort values to get which item is placed with the most quantity

how to show which item is placed with the most quantity from this data?

how to show which item is most ordered groupby choice_description?

url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'
df= pd.read_csv(url, sep = 't')

My data

order_id    quantity    item_name   choice_description  item_price
1   1   Chips and Fresh Tomato Salsa    NULL    $2.39 
1   1   Nantucket Nectar    [Apple] $3.39 
2   2   Chicken Bowl    [Tomatillo-Red Chili Salsa (Hot), [Black Beans, Rice, Cheese, Sour Cream]]  $16.98 
3   1   Chicken Bowl    [Fresh Tomato Salsa (Mild), [Rice, Cheese, Sour Cream, Guacamole, Lettuce]] $10.98 
3   1   Side of Chips   NULL    $1.69 
4   1   Steak Burrito   [Tomatillo Red Chili Salsa, [Fajita Vegetables, Black Beans, Pinto Beans, Cheese, Sour Cream, Guacamole, Lettuce]]  $11.75 
4   1   Steak Soft Tacos    [Tomatillo Green Chili Salsa, [Pinto Beans, Cheese, Sour Cream, Lettuce]]   $9.25 
...
...

Advertisement

Answer

This will list all ties (if any).

df.loc[df["quantity"] == df["quantity"].max(), "item_name"]

Output:

3598    Chips and Fresh Tomato Salsa
Name: item_name, dtype: object
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement