Home > Net >  i want to remove a substring from a link of strings in a column of a dataframe in python
i want to remove a substring from a link of strings in a column of a dataframe in python

Time:11-29

df_bucket['Uri'].str.replace('www.','')

these are the link in a dataframe:

'https://www.durbine.com.bd/Upload/vimg/20211104/N20211104044257_270256_Jgh3eI3dJo7Lv2GuGiWswwwW.jpg', 'https://www.durbine.com.bd/Upload/vimg/20211104/N20211104044808_280753_miGVs4defXAMXcmFM1XJwwwX.jpg'

but the result is:

'https://durbine.com.bd/Upload/vimg/20211104/N20211104044257_270256_Jgh3eI3dJo7Lv2GuGiWs.jpg', 'https://durbine.com.bd/Upload/vimg/20211104/N20211104044808_280753_miGVs4defXAMXcmFM1XJ.jpg'

it is also removing wwwX and wwwW from the last.

CodePudding user response:

You want www. with a literal dot, so turn off regex in your call to str.replace:

df_bucket['Uri'].str.replace('www.', '', regex=False)

Or, if you want to use str.replace in default regex mode, then escape the dot with backslash:

df_bucket['Uri'].str.replace('www\.', '')
  • Related