python - 熊猫排序值以获取最多放置的项目
问题描述
如何从该数据中显示哪个项目放置的数量最多?
如何显示哪个项目是最有序的 groupby 选择描述?
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
...
...
解决方案
- 如果要显示所有数据:
df.sort_values('quantity', ascending=False)
输出:
order_id quantity item_name choice_descri item_price
1443 15 Chips and Fresh Tomato Salsa NaN $44.25
1660 10 Bottled Water NaN $15.00
1559 8 Side of Chips NaN $13.52
1443 7 Bottled Water NaN $10.50
...
- 如果您只想显示第一行:
df.sort_values('quantity', ascending=False).head(1)
输出:
order_id quantity item_name choice_descri item_price
1443 15 Chips and Fresh Tomato Salsa NaN $44.25
- 或者,如果您只想显示名称:
df.sort_values('quantity', ascending=False).head(1).item_name
3598 Chips and Fresh Tomato Salsa
Name: item_name, dtype: object
推荐阅读
- phabricator - 将 Phabricator(Maniphest)任务字段的查看访问权限限制为仅特定用户组?
- sql - 如何修复 SQL Server 并转换和替换查询?
- python-3.x - 如何查看动态生成的纸浆方程
- python - iPython 在 OS X 上的 Visual Studio Code 中自动启动
- delphi - Delphi TTimer 在 Win 10 中提供不寻常的结果
- ios - 哪种数据模型最适合存储类似 instagram 的数据?
- postgresql-9.2 - Postgresql 未对用户进行身份验证
- swift - 如何使用继承创建节点?
- python - 使用公共数据源同步的 QListWidget
- php - 在 WooCommerce 中隐藏缺货的相关产品