Reputation: 1197
I have two columns such as this:
wind play
yes no
no yes
no no
yes yes
If the value in the wind
column is yes
, I want to extract the corresponding values in the play
column irrespective of whether the value in that column is yes
or no
.
I wrote this for
loop to do this but, I am not sure if this is the right way to do such an operation? tar_attr_labels
is the play
column.
for val in labelFreq.keys(): # dict contains yes and no
dataSubset = [entry for entry in tar_attr_labels if val]
.....
Upvotes: 0
Views: 615
Reputation: 4987
I suppose your labelFreq
variable has a dictionary with your wind
column as key and play
column as value.
If this is true, here is what you want to do:
data_subset = {wind: play for wind, play in labelFreq.items() if wind == 'yes'}
Upvotes: 1