put all the items containing a certain string in a dataframe in another column

The dataframe I have right now looks like this

In[1]: df
Out[1]:
index    yesterday    today    tomorrow   
1        apple_1      banana_3 cherry_4   
2        pear_2       apple_4  blueberry_1 
3        kiwi_3       orange_6 banana_2   
4        apple_1      melon_3  banana_4  

I want to record all the apples and put it in another column/series like

index    yesterday    today    tomorrow    apple
1        apple_1      banana_3 cherry_4    apple_1
2        pear_2       apple_4  blueberry_1 apple_4
3        kiwi_3       orange_6 banana_2    nan
4        apple_1      melon_3  banana_4    apple_2
  1. IDK which column will contain an apple
  2. IDK what else is with the apple

Thanks for the help!

Answer

Try with startswith then where mask then as nan and do ffill

df['new'] = df.where(df.apply(lambda x : x.str.startswith('apple'))).ffill(1).iloc[:,-1]
df
Out[149]: 
      yesterday     today     tomorrow      new
index                                          
1       apple_1  banana_3     cherry_4  apple_1
2        pear_2   apple_4  blueberry_1  apple_4
3        kiwi_3  orange_6     banana_2      NaN
4       apple_1   melon_3     banana_4  apple_1