Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to remove url in python colab?

I am doing data cleaning for my dataset.
How to remove the link "pic.twitter.com…." in Python for colab?
here’s the picture of the link I want to remove

Any suggestions are much appreciated. Thanks.

#remove other links
def removelinks(text):
  
**  links = re.sub(r'????')**
  return links.sub(r'',text)
  train_df['clean tweet']= train_df['clean tweet'].apply(lambda x:  removelinks(x))
train_df.head()

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can try (regex101):

df['clean tweet'] = df['clean tweet'].str.replace(r'pic\.twitter\.com\S*\s*', '', regex=True)
print(df)

Prints:

   clean tweet
0  some tweet1
1  some tweet2
2  some tweet3

Initial df:

                             clean tweet
0                            some tweet1
1  pic.twitter.com/some_link some tweet2
2                            some tweet3
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading