gpt4 book ai didi

python - 过滤具有整数列表的python输出

转载 作者:行者123 更新时间:2023-12-01 03:18:19 26 4
gpt4 key购买 nike

我已将 csv 文件导入到 PyCharm 并尝试从行中打印特定列表,到目前为止是成功的。我的输出为整数列表。我正在尝试过滤列表并仅打印大于特定数字(本例中为 500)的整数,但不知道如何以及在何处使用“if”条件。

这是我的代码:

import csv

f = open('C:\Python36-32\movies.csv', encoding='utf')

csv_f = csv.reader(f)
next(csv_f, None)

for row in csv_f:
content = row[3]

print(content)

f.close()

这是输出:

489
472
615
784
251
365
956
902
397
668
...

输出继续。

感谢您的帮助!

最佳答案

试试这个,

import csv

with open(filename, 'r') as f:
reader = csv.reader(f, delimiter=',')
next(reader, None) # skip the headers

for row in reader:
if int(row[3]) > 500:
print(row)

关于python - 过滤具有整数列表的python输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42254556/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com