2 回答
TA贡献1793条经验 获得超6个赞
请str.replace以以下字符串开头@
样本数据
text
0 News via @livemint: @RBI bars banks from links
1 Newsfeed from @oayments_source: How Africa
2 is that bitcoin? not my thing
tweetscrypto['clean_text']=tweetscrypto['text'].str.replace('(\@\w+.*?)',"")
尽管如此,仍可以捕获@而无需逃脱,如所指出的@baxx
tweetscrypto['clean_text']=tweetscrypto['text'].str.replace('(@\w+.*?)',"")
clean_text
0 News via : bars banks from links
1 Newsfeed from : How Africa
2 is that bitcoin? not my thing
TA贡献1843条经验 获得超7个赞
在这种情况下,出于可读性的目的,定义一个方法可能比使用 lambda 更好。
def clean_text(X):
X = X.split()
X_new = [x for x in X if not x.startswith("@")
return ' '.join(X_new)
tweetscrypto['clean_text'] = tweetscrypto['text'].apply(clean_text)
添加回答
举报