I need to fill cells in a column based off if another column contains a certain string.
I need to fill column B based off what's in C. Like if C contains 'hello;', then fill the corresponding cell in B with 'greet'. Then if C contains 'bye;', fill the corresponding cells in B with 'farewell'.
df1
A B C D
0 w hello; Jon q
1 x bye; Jon r
2 y hello; Jack s
3 z bye; Jack t
df1['B'] = np.where(df1['C'].str.contains('hello;'), 'greet', '')
df1['B'] = np.where(df1['C'].str.contains('bye;'), 'farewell', '')
This works; however, the next line of code overwrites the 'greet' from the first line. So I'm not sure how to combine the conditionals so they don't overwrite each other. What I want the end result to be is
df1
A B C D
0 w greet hello; Jon q
1 x farewell bye; Jon r
2 y greet hello; Jack s
3 z farewell bye; Jack t