I have a dataframe and a list:
b = pd.DataFrame({'text': ["like","reduce","carbon","emissions","reduce carbon emissions"],'score': [1,-1,-1,-1,1]})
a = ['like', 'reduce carbon emissions']
I would like to find the indexes where the words in a
are in b
so that I can sum score
accordingly.
I am pretty sure this has been asked many times but I can't find any reference.
Can anyone help me?
Thanks!
CodePudding user response:
Try with isin
b.loc[b.text.isin(a)]
Out[45]:
text score
0 like 1
4 reduce carbon emissions 1