如何显示该数据中放置数量最多的项目?
如何显示哪个项目排序最多groupby choice_description?
url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'
df= pd.read_csv(url, sep = '\t')
我的数据
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
...
...
3条答案
按热度按时间v1uwarro1#
输出:
输出:
3bygqnnd2#
这将列出所有关系(如果有)。
输出:
r8uurelv3#
数量最多的项目-
chipo.groupby(['item_name'])['quantity'].sum().sort_values(ascending=False).index.values[0]
按选择排序最多的组-
chipo.groupby(['choice_description'])['quantity'].sum().sort_values(ascending=False).index.values[0]