python - 从数据框中删除列中以 "@"开头的单词

我有一个名为 tweetscrypto 的数据框,我试图从“文本”列中删除所有以字符“@”开头的单词,并将结果收集到新列“clean_text”中。其余单词应保持完全相同:

tweetscrypto['clean_text'] = tweetscrypto['text'].apply(filter(lambda x:x[0]!='@', x.split()))

好像不行。有人可以帮忙吗?

提前致谢

最佳答案

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

关于python - 从数据框中删除列中以 "@"开头的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63891996/

相关文章:

vector - 如何在 Ada 中添加向量

python - 使用 Pandas 和 R 将序列号连接到组中的每一行

f# - 在 F# 中添加两个元组

python - 如何将带有元组键的 python 字典转换为 pandas 多索引数据框?

php - 交响乐 5 : how to check if user is banned or no

javascript - 悬停时高效的 JS 事件监听器

amazon-web-services - 服务器端加密与客户端加密 - Amazon S3

python - Python 中的 Marching Square 算法

python - 为什么在 Pi 的整数倍处 torch.sin() 和 numpy.sin() 的

java - Hibernate: OneToOne: 同一类型的两个字段