Linked Questions

Popular Questions

Replacing an string in a dataframe python

Asked by At

I have a (7,11000) dataframe. in some of these 7 columns, there are strings. In Coulmn 2 and row 1000, there is a string 'London'. I want to change it to 'Paris'. how can I do this? I searched all over the web but I couldnt find a way. I used theses commands but none of them works:

df['column2'].replace('London','Paris')
df['column2'].str.replace('London','Paris')
re.sub('London','Paris',df['column2'])

I usually receive this error:

TypeError: expected string or bytes-like object

Related Questions