I am looking for a value within a list object in a DataFrame:
This is my code:
for tags in Questions["Tags"]:
if "deep-learning" in tags:
Questions["DL-flag"] = 1
The column that I am looking into looks like this: [python, keras, tensorflow, cnn, probability]
According to my code looking for deep-learning in that example should result in false, but that is not what is happening, since all the column is returning true for each row
Could you help me out?
CodePudding user response:
This line Questions["DL-flag"] = 1
only puts 1
in every row of DL-flag
and that explains` your observation.
This is how you can achieve your goal:
Questions['DL-flag'] = Questions['Tags'].apply(lambda l: 'deep-learning' in l)
You apply
this lambda l: 'deep-learning' in l
function over every element of the Series
Questions['Tags']