number 是 csv 中的字符串?

number is a string in a csv?

我刚刚阅读了有关常见错误消息的几个答案,

TypeError: '>=' not supported between instances of 'str' and 'int

问题是所有这些都是基于 input() 命令。我的问题是我正在尝试比较 csv 文件中的值,如下所示:

math_mavens = []
for row in complete_data_pd:
    if "math_score" >= 70:
        math_mavens.append("student_name")
num_math_mavens = len(math_mavens)
percent_math_mavens = num_math_mavens / total_students

我知道必须将字符串转换为 int,但我不明白在没有 input() 的情况下该怎么做。数字(或字符串)直接来自 csv。

由于没有人发布单独的答案,我在这里重新发布 Ben Pap 的评论作为有效的答案:

complete_data_pd 是数据框吗?和 math_score 专栏?如果是这样,你可以这样做来获得你的 percent_math_mavens:

len(complete_data_pd[complete_data_pd['math_score'] >= 70])/total_students 

– Ben Pap 1 月 21 日在 22:21