Given this data frame:
>>> a = pd.DataFrame(data={'words':['w1','w2','w3','w4','w5'],'value':np.random.rand(5)})
>>> a
value words
0 0.157876 w1
1 0.784586 w2
2 0.875567 w3
3 0.649377 w4
4 0.852453 w5
>>> b = pd.Series(data=['w3','w4'])
>>> b
0 w3
1 w4
I'd like to replace the elements of value with zero but only for the words that match those in b.
The resulting data frame should therefore look like this:
value words
0 0.157876 w1
1 0.784586 w2
2 0 w3
3 0 w4
4 0.852453 w5
I thought of something along these lines: a.value[a.words==b] = 0 but it's obviously wrong.