Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.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 从tweet中删除#,和RT_Python_Twitter - Fatal编程技术网

Python 从tweet中删除#,和RT

Python 从tweet中删除#,和RT,python,twitter,Python,Twitter,我有数百万条推文,我想从推文中删除“#”和“RT”。例如:“RT@ABC:Meslekten ihraçedilen#polis müdürüMuratïetiner”应给出输出“@ABC:Meslekten ihraçedilen polis müdürüMurat etiner” 以下是我目前掌握的代码: # coding:utf-8 import sys x = "RT @zamancomtr: Meslekten ihraç edilen polis müdürü Murat Çetin

我有数百万条推文,我想从推文中删除
“#”
“RT”
。例如:
“RT@ABC:Meslekten ihraçedilen#polis müdürüMuratïetiner”
应给出输出
“@ABC:Meslekten ihraçedilen polis müdürüMurat etiner”

以下是我目前掌握的代码:

# coding:utf-8
import sys
x = "RT @zamancomtr: Meslekten ihraç edilen polis müdürü Murat Çetiner: Bana takdir belgesi veren     BM de mi paralel? http://t.co/sd5N6yaZzv http:…"
y = ' '.join(re.sub("(@[A-Za-z0-9]+)|([^0-9A-Za-z \t])|(\w+:\/\/\S+)"," ",x).split())
print y
您可以使用下一个代码:

z = lambda x: re.compile('\#').sub('', re.compile('RT @').sub('@', x, count=1).strip())
print z(x)
首先
re.compile('RT@').sub('@',x,count=1)
替换昵称前的第一个
'RT'
。如果要删除post中的任何转发标签,只需从代码中删除
count=1
。有必要使用掩码“RT@”,因为“RT”可能出现在tweet正文中


同样地,
re.compile('\\#')
从tweet中删除所有的hashtag。

那么该代码做什么呢?问题是什么,;它应该做什么呢?到目前为止,您尝试了什么来修复它?代码删除了tweet中的所有特殊字符,我想使用regex,但我不确定如何使用它。然后,也许您应该开始学习如何使用它:我可以使用index删除RT吗?如果可以,我如何通过查找“,”和“@”的索引位置来删除RT然后切掉他们之间的RT。。下面是代码:f=open(“clean.txt”,“r”)用于f:comma\u pos=item中的项目。find(“,”)在\u pos=item处打印逗号位置。find(“@”)在\u pos处打印