Q:

Searching for a substring in a dataframe and replacing it

I have a condition where spurious data is created and I am trying to clean it. 
eg...
www.one@foxturn.com/!ut/5 #RealLink
www.one@foxturn.com/ut1/5_RTFDEERERTGFEFD # System adds junks to it
www.one@foxturn.com/ut1/5_dvkerfddfrejermsdkasmf # System adds junks to it

I am trying to clean this up by dropping everything after !ut 
So far I have tried :
SPA_MX = Mexico['Page URL'].str.startswith("http://www.www.one@foxturn.com/ut1")

but this returns a boolean. 
I would like advise on the most efficient way to achieve this.

A:

You can do this using apply on the column and then use find to return the index of the pattern and slice the str if found:
In[69]:

df['url'].apply(lambda x: x[:x.find('!ut') + 3] if x.find('!ut') != -1 else x)

Out[69]: 
0                             www.one@foxturn.com/!ut
1           www.one@foxturn.com/ut1/5_RTFDEERERTGFEFD
2    www.one@foxturn.com/ut1/5_dvkerfddfrejermsdkasmf
Name: url, dtype: object

