Is there a reason you cannot use the split function and then map the function to the column?
As per the first example, this will work:
def word_scrape(whole_string):
outside_v = whole_string.split(" v ")
first_word = outside_v[0].split(" ")[0]
last_word = outside_v[1].split(" ")[1]
return first_word + " v " + last_word
for i,text in enumerate(df.ix[:,'text']):
df.ix[i,'text'] = word_scrape(text)
for fault tolerance for single word entries, use:
def word_scrape(whole_string):
try:
outside_v = whole_string.split(" v ")
first_word = outside_v[0].split(" ")[0]
last_word = outside_v[1].split(" ")[1]
return first_word + " v " + last_word
except:
outside_v = whole_string.split(" v ")
first_word = outside_v[0].split(" ")[0]
last_word = outside_v[1].split(" ")[0]
return first_word + " v " + last_word
for i,text in enumerate(df.ix[:,'text']):
df.ix[i,'text'] = word_scrape(text)
As per the second example, this will work:
def word_scrape(whole_string):
outside_v = whole_string.split(" v ")
first_word = outside_v[0].split(" ")[0]
last_word = outside_v[1].split(" ")[0]
return first_word + " v " + last_word
for i,text in enumerate(df.ix[:,'text']):
df.ix[i,'text'] = word_scrape(text)