You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pandas DataFrame自定义筛选排序:筛选Planes数据seating>350并展示指定列

实现代码

你可以通过Pandas的列选取、条件筛选、排序三个步骤完成需求,代码示例如下:

# 链式写法,默认按seating列升序排序
result = Planes[['model', 'seating']][Planes['seating'] > 350].sort_values(by='seating')

# 若需要按载客量从大到小降序排序,可补充ascending参数
# result = Planes[['model', 'seating']][Planes['seating'] > 350].sort_values(by='seating', ascending=False)

代码逻辑说明

  • 通过[['model', 'seating']]选取需求指定保留的两个字段
  • 通过布尔索引Planes['seating'] > 350筛选出载客量大于350的行
  • 最后调用sort_values()方法按seating列数值完成排序

内容的提问来源于stack exchange,提问作者emre570

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 15:36:03