如何使用python查找数据中满足条件的次数?

如何使用python查找数据中满足条件的次数?,python,Python,我有大量的数据,我试图确定有多少行数据包含播放和0。这被列为板材外观的计数,但是,我不确定如何仅打印最终值,而不是所有值。我觉得这可能有一个直截了当的答案,但是,我对python非常陌生。任何帮助都将不胜感激 for j in range(i+46,i+150,1): temp_array2 = lines[j].rstrip().split(",") if temp_array2[0] == "play" and temp_array2[2] == "1":

我有大量的数据,我试图确定有多少行数据包含播放和0。这被列为板材外观的计数,但是,我不确定如何仅打印最终值,而不是所有值。我觉得这可能有一个直截了当的答案,但是,我对python非常陌生。任何帮助都将不胜感激

for j in range(i+46,i+150,1):
      temp_array2 = lines[j].rstrip().split(",")
      if temp_array2[0] == "play" and temp_array2[2] == "1":
            count_of_plate_appearances=count_of_plate_appearances+1
            print(count_of_plate_appearances)
输出是

1
2
3
4
5
6
7
8
1
2
3
4
5
6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
3
4
5
6
7
但是,我希望输出是

8
6
15
7

提前谢谢你

您在迭代每个j之后打印结果。我认为您应该在迭代每个I之后打印结果

试试这个

for j in range(i+46,i+150,1):
  temp_array2 = lines[j].rstrip().split(",")
  if temp_array2[0] == "play" and temp_array2[2] == "1":
        count_of_plate_appearances=count_of_plate_appearances+1
print(count_of_plate_appearances)
从何处开始打印。

您只需将印版外观的打印计数放置在正确的位置;i、 e,在每次迭代结束时
for i in range(4):
    count_of_plate_appearances=0    

    for j in range(i+46,i+150,1):
          temp_array2 = lines[j].rstrip().split(",")
          if temp_array2[0] == "play" and temp_array2[2] == "1":
                count_of_plate_appearances=count_of_plate_appearances+1
     print(count_of_plate_appearances)