我如何删除以“\u.”开头的所有术语
count_all = Counter()
for sentence in tweets[:100]:
cleaned_terms = [term for term in preprocess(sentence.lower()) if term not in stop]
count_all.update(cleaned_terms)
print count_all.most_common(5)产出:
#[(u'#halloween', 100), (u'\ud83d', 52), (u'\u2026', 28), (u'\ud83c', 24), (u'halloween', 14)]发布于 2015-11-02 01:51:49
\uXXXX对应于Unicode字符(例如,2026 =单个字符省略号,.)。找到非ASCII的最简单的选择就是检查ord(term[0]) > 255是否在您的理解中,但是这是否真的是您想要做的可能取决于您特定的用例。
https://stackoverflow.com/questions/33469428
复制相似问题