Reputation: 3792
I have a pandas dataframe train with the following content in line 24549
train.iloc[24549,:]
>>>
id 79571
product_uid 123177
product_title Charlotte Pipe 3/4 in. PVC Sch. 40 90-Degree S...
search_term 3/4 in pvc assesories
relevance 2.67
Name: 24549, dtype: object
I want to to replace 'assesories' with 'accessories' in train.iloc[24549,3]
If I do:
train = train.replace('assessories','accessories')
Whenever I check the df value after this command, the word in the above dataframe element is still 'assessories'.
However, if I do:
c = train.iloc[24549,3]
c = c.replace('assessories','accessories')
c
>>>> '3/4 in pvc accessories'
I am still scratching my head over this. I do not want to iterate through the df but rather do a vectorized implementation. Do you have any ideas how to do that?
Upvotes: 0
Views: 69
Reputation: 3792
the right command is not
train = train.replace('assessories','accessories')
but
train = train.str.replace('assessories','accessories')
Thanks to my friend Lucas Eustaquio for pointing this out.
Upvotes: 1