在线实时匹配正则表达式的网站在此,很好用
[#].*?\s
import re
print(re.findall(r"[#].*?\s",txt))
就全都提取出来了
接着把这些hashtag删掉(注意list对象remove和pop方法不同)
li = [1, 2, 3, 4]
li.remove(3)
print(li)
# Output [1, 2, 4]
li = [1, 2, 3, 4]
li.pop(2)
print(li)
# Output [1, 2, 4]
就可以进行词频分析了(这些标签出现频率太高影响正文词频的统计)
with open(r"NLTK's list of english stopwords", 'r', encoding='utf-8') as f:
lines = f.readlines()
for line in lines:
stop_words.append(line.strip())
dict1={}
for word in words:
if word in stop_words:
continue
else:
dict1[word]=dict1.get(word,0)+1
dict1