繁体   English   中英

如何从 csv 文件中找到最大年龄,然后返回该人的姓名?

[英]How do I find the max age from a csv file and then return that person's name?

标题几乎概括了我的问题。 这是我到目前为止的代码:

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

你可以尝试这样的事情。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM