Suppose I have a dataframe,
data
id URL
1 www.pandora.com
2 m.jcpenney.com
3 www.youtube.com
4 www.facebook.com
I want to create a new column based on a condition that if the URL contains some particular word. Suppose if it contains 'youtube', I want my column value as youtube. So I tried the following,
data['test'] = 'other'
so once we do that we have,
data['test']
other
other
other
other
then I tried this,
data[data['URL'].str.contains("youtub") == True]['test'] = 'Youtube'
data[data['URL'].str.contains("face") == True]['test'] = 'Facebook'
Though this runs without any error, the value of the test column, doesn't change. It still has other only for all the columns. When I run this statement, ideally 3rd row alone show change to 'Youtube' and 4th to 'Facebook'. But it doesn't change. Can anybody tell me what mistake I am doing here?