0
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)

My csv file has a row for the make of a series of cars at index 2. I want the output to return a list of the make a a car along with the number of times the make appears in the column.

so far this code only returns {2:1}.

What am I missing?

0 Answers0