import csv
import matplotlib.pyplot as plt
import functools
import operator
f=open("/Users/local/Documents/test_scripts/practice_2.csv",'r')
c=csv.reader(f)
names=["James","John","Harry","Jim"]
labels=[]
def namecount(n):
count=[]
for row in c:
if row[5]==n:
count.append(1)
value=functools.reduce(operator.add,count)
return value
l=map(namecount,names)
print(list(l))
Мой желаемый результат: [44,48,30,1]
Но когда я запускаю код, я получаю следующую ошибку:
File "/Users/290006411/PycharmProjects/Practice/pie_one.py", line 18, in <module>
print(list(l))
File "/Users/290006411/PycharmProjects/Practice/pie_one.py", line 14, in namecount
value=functools.reduce(operator.add,count)
TypeError: reduce() of empty sequence with no initial value
Не уверен в ошибке .