首页 > 解决方案 > 如何从 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”所指数据的图片:

player_data

标签: pythonpython-3.x

解决方案


你可以尝试这样的事情。

max_player = sorted(player_data, key=lambda c : x[2])

推荐阅读