opened_file = open(r'C:\Users\lalus\Desktop\Datasets\cars.csv')
from csv import reader
read_file = reader(opened_file)
cars_data = list(read_file)
def howMany(index):
a_list = {}
for row in cars_data[1:]:
if row[index] in a_list:
a_list[index] += 1
else:
a_list[index] = 1
return a_list
make_count = howMany(2)
print(make_count)
我的 csv 文件在索引 2 处有一行用于一系列汽车的制造。我希望输出返回制造汽车的列表以及制造在列中出现的次数。
到目前为止,此代码仅返回 {2:1}。
我错过了什么?