Blocked from step 2 [Solved]

Hey guys,

It’s quite frustrating since I did the lessons without any problems, but I have massive problems with such a basic task as importing the data. After failing to create a dictionary of any form anyhow and getting all the errors I could get (DictReader not subscriptable and Unsupported Operation : not readable, being the most infuriating), I just don’t know what to do. So, here’s what I had in mind after the import csv :

#Preparing the parsing of data :
age = []
sex = []
bmi = []
children = []
smoker = []
region = []
charges = []

#Creating a function to isolate each data:
def data_by_lists(liste, csv_file, column):
    with open(csv_file) as insurance_csv:
        insurance_dict = csv.DictReader(insurance_csv)
        for row in insurance_dict:
            liste.append(row[column])
    return liste

#Implementing the function
data_by_lists(age, 'insurance.csv', 'age')
data_by_lists(sex, 'insurance.csv', 'sex')
data_by_lists(bmi, 'insurance.csv', 'bmi')
data_by_lists(children, 'insurance.csv', 'children')
data_by_lists(smoker, 'insurance.csv', 'smoker')
data_by_lists(region, 'insurance.csv', 'region')
data_by_lists(charges, 'insurance.csv', 'charges')

The only output I have is :

['charges', 'charges', 'charges', 'charges']

How come I don’t have any values in here ?

In the last line before return, in my function, instead of

liste.append(row[column])

I have tried

liste.append(insurance_dict[column])

which only leads to a DictReader not subscriptable error.

Thanks for any feedback!

Edit : problem solved, my insurance.csv file didn’t have anything on it, but the headers, three times.

And there’s no need for implementing so much function, it works. So now I’m heading to my plans!