Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 删除以“开始”开头的单词@&引用;在数据帧的列中_Python_Pandas_Dataframe_Split - Fatal编程技术网

Python 删除以“开始”开头的单词@&引用;在数据帧的列中

Python 删除以“开始”开头的单词@&引用;在数据帧的列中,python,pandas,dataframe,split,Python,Pandas,Dataframe,Split,我有一个名为tweetscrypto的数据框,我正试图删除“text”列中以“@”开头的所有单词,并将结果收集到一个新的“clean_text”列中。其余的单词应该保持完全相同: 它似乎不起作用。有人能帮忙吗 提前感谢在这种情况下,定义一个方法可能比使用lambda更好,因为它主要用于可读性目的 def clean_文本(X): X=X.split() X_new=[X表示X中的X,如果不是X.startswith(“@”) 返回“”。加入(X_新) tweetscrypto['clean_t

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

它似乎不起作用。有人能帮忙吗


提前感谢

在这种情况下,定义一个方法可能比使用lambda更好,因为它主要用于可读性目的

def clean_文本(X):
X=X.split()
X_new=[X表示X中的X,如果不是X.startswith(“@”)
返回“”。加入(X_新)
tweetscrypto['clean_text']=tweetscrypto['text']。应用(clean_text)
样本数据

                                       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

转义
@
符号是否有必要?似乎
str.replace(“(@\w+”,”)
在这里可以用,我缺少什么吗?@baxx你是对的。它可以用。作为editfunnywise包含,我尝试为每个链接(每个以“http”开头的单词)做同样的事情但它似乎不起作用…我尝试了tweetscrypto['clean_text']=tweetscrypto['text'].str.replace(“(\http\w+.*?”,”)有人知道为什么吗?非常感谢
                                       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+.*?)',"")
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