arrays - python-meeting two column criteria in one dataset and outputting to a new list or printing count -
this simple question don't know i'm doing wrong. trying create new list if 2 columns in data have 1 in 1 of columns , listed female in separate column. going count number of observations in new list. can not create new list , check if whether meet 2 conditions count+1. main problem don't think if statement correct because when create list. it's blank. know there matches meet criteria know array shouldn't blank. being stupid?
thanks help.
>>> data_s=[] in data: if data[0::,1]=="1" , data[0::,4]=="female": data_s.append(i) data_s=numpy.array(data_s) >>> data_s [] >>>
look conditional indexing, , try this:
data_s = [entry entry in data if entry[1]=="1" , entry[4]=="female"]
in code segment, if statement should tested on (not data) since using loop through elements of data
Comments
Post a Comment