i have a list of sentences and i need to replace each word by a word from a data frame column. it is a one to one correspondence. here's my code:
def replace_words(x):
z = [word for line in x for word in line.split()]
for i in range(0 ,(len(z)-1)):
z[i] = str.replace(z[i],dataframe[i])
return z
which eventually gives an error "cant assign to function call" . this is how the data looks like:
x = ['I love flappy brd' , 'i got a platium medal','i hammred my fone'] .
now computing z, gives me:
z = ['I','love','flappy','brd','i','got','a','platium','medal','i','hammred','my','fone']
dataframe is a series(table like object) which has one column , and each row consists of 1 word it looks like this:
so now i need to replace words in z with these words(correct ones)in image i.e dataframe .. how do i do that?
z[i] = z[i].replace()? - TomAugspurger