Bruhlickd
Bruhlickd

Reputation: 73

Replace single string in a pandas dataframe column

I have a Pandas column with the path of some pictures like this:

http://localhost:8888/view/Desktop/directory1/directory2/john.jpeg
http://localhost:8888/view/Desktop/directory1/directory2/alice.jpeg
http://localhost:8888/view/Desktop/directory1/directory2/joseph.jpeg
...

I need to replace /view/ for /files/. Wichi Pandas method do I have to use to iterate and doing it?

Upvotes: 0

Views: 197

Answers (1)

user17242583
user17242583

Reputation:

Use .str.replace:

df['YOUR COLUMN'] = df['YOUR COLUMN'].str.replace('/files/', '/views/')

Output:

                                                             YOUR COLUMN
0    http://localhost:8888/files/Desktop/directory1/directory2/john.jpeg
1   http://localhost:8888/files/Desktop/directory1/directory2/alice.jpeg
2  http://localhost:8888/files/Desktop/directory1/directory2/joseph.jpeg

Upvotes: 1

Related Questions