I am stuck with my project about the US Medical Insurance Costs Portfolio, and I need your help to go ahead in my scope.
I considered 3 variables for my analysis:
I created a list of lists made by the 3 variables called ages_smokes_regions with the following aspect:
[(19, 'yes', 'southwest'), (18, 'no', 'southeast'), (28, 'no', 'southeast'), (33, 'no', 'northwest'), (32, 'no', 'northwest'), ... , ]
I want to extract a new list from this one, containing only the record with smoking status = yes and age <= 21 years.
How you suggest to do?
I tried this nested loop:
ages_smokers_regions_new =  for record in ages_smokers_regions: for e1, e2 in record: if e1 <= 21 and e2 == 'yes': ages_smokers_regions_new.append(record)
but I get this type error message:
TypeError Traceback (most recent call last) <ipython-input-94-ecfd3a775a3f> in <module> 2 3 for record in ages_smokers_regions: ----> 4 for e1, e2 in record: 5 if e1 <= 21 and e2 == 'yes': 6 ages_smokers_regions_new.append(record) TypeError: cannot unpack non-iterable int object
Thank you for you help!!