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
I have tried
which only leads to a DictReader not subscriptable error.
Thanks for any feedback!