简体   繁体   English

我正在使用 python 读取一个 csv 文件,我想从 csv 文件(PYTHON)中获取具有正值的行

[英]I am reading a csv file using python and i want to get rows which has postive values from the csv file(PYTHON)

Hi I am reading a csv file using python and i want to get rows which has postive values from the below csv file.嗨,我正在使用 python 读取一个 csv 文件,我想从下面的 csv 文件中获取具有正值的行。

below is the code that i am trying in python下面是我在 python 中尝试的代码

import csv
with open('fa.csv','r') as fa:
    test=csv.reader(fa)
    for i in test:
        if int(i[1])<=31:
            print(i[0],i[1])
fa.close()

testing1.com -1172
testing2.com -1171
testing3.com -1171
testing4.com 250
testing5.com 120
testing6.com 45
testing7.com 39

i am looking for the output

testing6.com 45
testing7.com 39

If i is equal to the url and then the integer you can just do如果 i 等于 url 然后 integer 你可以做

if int(i[1]) >= 0:
    print(i[0], i[1]) #Because every number over 0 is positve

The only thing I'm not sure is that you say you don't want 120 and 250 although 120 and 250 are both positive, so this question isn't quite clear我唯一不确定的是你说你不想要 120 和 250 虽然 120 和 250 都是积极的,所以这个问题不是很清楚

you are using the wrong bigger than it should be if int(i[1])>=31: rather than int(i[1])<=31: and i would change the 31 to a 0 .如果int(i[1])>=31:而不是int(i[1])<=31:并且我会将31更改为0 ,则您使用的错误大于应有的大小。

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

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