python - 如何从 csv 文件中找到最大年龄,然后返回该人的姓名?
问题描述
标题几乎概括了我的问题。这是我到目前为止的代码:
def oldest_player(): #what is the name of the oldest player?
for i in player_data:
row_idx = player_data.index(i)
age_list = []
zero_age = 0
if cell(row_idx, "Age") > zero_age:
if cell(row_idx, "Age") > age_list[0]:
curr_age = cell(row_idx, "Age")
age_list.clear()
age_list.append(curr_age)
else:
continue
return age_list
oldest_player()
或多或少,我在问如何在 csv 文件中找到列的最大值,然后如何返回与该数据条目对应的名称。
谢谢!
编辑:这是“player_data”所指数据的图片:
解决方案
你可以尝试这样的事情。
max_player = sorted(player_data, key=lambda c : x[2])
推荐阅读
- node.js - 如何使用节点 js 连接安装在不同服务器上的 cassandra
- php - 如何使用 yii2 在 gridview rowOption 中使用 mysql 查询更改行颜色
- java - 运行 Kafka 性能流量时出现错误“此服务器不是该主题分区的领导者”
- c++ - 值传递和 std::move 优于传递引用的优点
- r - R:元组的布尔测试
- python - Python在类继承安全中重新创建实例
- python - 如何小写熊猫数据框上的 JSON 对象
- amp-html - 使用 amp-date-picker 计算日期差异
- javascript - isSupported' 未定义的 jquery
- java - 如何测试 gRPC(功能和集成测试)