0

I need to replace words starting with www. with the rest of the link. For example:

www.stackoverflow.com 

with

stackoverflow.com

I am using pandas. The column that contains the links is called COL1. I have 1000 rows. I have tried with

df.loc[df['COL1'].str.startswith('www.', na=False), 'NEW_COL'] 

but I do not know what I should replace with in order to take the rest of the link.

Could you please give me advice on it?

still_learning
  • 776
  • 9
  • 32

1 Answers1

1

You can use str.replace with regex pattern:

df['COL1'] = df['COL1'].str.replace('^(www\.)', '')
Quang Hoang
  • 146,074
  • 10
  • 56
  • 74