numbers = [] numbers2 = [] with open("100.csv","r") as fh: header = fh.readline() for line in fh: line = line.rstrip() data = line.split(';') numbers.append(float(data[2])) sample = int(data[1].split('_')[1]) if sample % 2 == 0: numbers2.append(float(data[2])) average = sum(numbers)/len(numbers) print(average) average = sum(numbers2)/len(numbers2) print(average)