regex 如何在python colab中删除url?

xkrw2x1b  于 2023-08-08  发布在  Python
关注(0)|答案(1)|浏览(80)

我正在为我的数据集进行数据清理。如何在Python for colab中删除链接“pic.twitter.com.”?here's the picture of the link I want to remove
任何建议都非常感谢。- 谢谢-谢谢

#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()

字符串

khbbv19g

khbbv19g1#

你可以试试(regex101):

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

字符串
印刷品:

clean tweet
0  some tweet1
1  some tweet2
2  some tweet3


初始df

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

相关问题