从字符串中删除表情符号
Removing Emojis from string
我在推特上做一些工作,很多推文看起来像
measles \xd2@theblackpenseur: gonorrhea rt @kylegotjokes: aids rt \xd2@cache___: my head itching so bad ?\xd3
我认为 \xd2
位是表情符号(尽管我可能错了,希望得到纠正)。
如何在保持字符串完好无损的情况下从字符串中删除它们?
根据您想要清理数据的程度,您可以使用
>>> import string
>>> tweet = 'measles \xd2@theblackpenseur: gonorrhea rt @kylegotjokes: aids rt \xd2@cache___: my head itching so bad ?\xd3'
>>> filter(lambda x: x in string.printable, tweet)
'measles @theblackpenseur: gonorrhea rt @kylegotjokes: aids rt @cache___: my head itching so bad ?'
这听起来有点自我推销(更多考虑到这个问题有多老),但我有一个 Python 库可以做到这一点(除其他外)。图书馆是 cucco 基本上你会做这样的事情:
from cucco import Cucco
cucco = Cucco()
cucco.remove_stop_words('Your text')
我在推特上做一些工作,很多推文看起来像
measles \xd2@theblackpenseur: gonorrhea rt @kylegotjokes: aids rt \xd2@cache___: my head itching so bad ?\xd3
我认为 \xd2
位是表情符号(尽管我可能错了,希望得到纠正)。
如何在保持字符串完好无损的情况下从字符串中删除它们?
根据您想要清理数据的程度,您可以使用
>>> import string
>>> tweet = 'measles \xd2@theblackpenseur: gonorrhea rt @kylegotjokes: aids rt \xd2@cache___: my head itching so bad ?\xd3'
>>> filter(lambda x: x in string.printable, tweet)
'measles @theblackpenseur: gonorrhea rt @kylegotjokes: aids rt @cache___: my head itching so bad ?'
这听起来有点自我推销(更多考虑到这个问题有多老),但我有一个 Python 库可以做到这一点(除其他外)。图书馆是 cucco 基本上你会做这样的事情:
from cucco import Cucco
cucco = Cucco()
cucco.remove_stop_words('Your text')