【发布时间】:2020-11-03 18:07:12
【问题描述】:
我在 python 中有一个函数,它使用分词器将一个句子分成单词。 问题是当我运行这个函数时,返回的输出是一个没有空格的单词。
- 实际句子:
'喜欢 Picture2Life.com !!! Y 所有有趣的应用程序 iphone而不是黑莓??!! '
- 结果:
'islovinpicturelifecomyallfunappsrforiphoneandnotblackberry'
结果必须是这样的: 是热爱图片 2 的生活。 com....
代码:
ppt = '''...!@#$%^&*()....{}’‘ “” “[]|._-`/?:;"'\,~12345678876543'''
#tekonize helper function
def text_process(raw_text):
'''
parameters:
=========
raw_text: text as input
functions:
==========
- remove all punctuation
- remove all stop words
- return a list of the cleaned text
'''
#check characters to see if they are in punctuation
nopunc = [char for char in list(raw_text) if char not in ppt]
# join the characters again to form the string
nopunc = "".join(nopunc)
#now just remove ant stopwords
words = [word for word in nopunc.lower().split() if word.lower() not in stopwords.words("english")]
return words
ddt= data.text[2:3].apply(text_process)
print("example: {}".format(ddt))
【问题讨论】:
-
似乎经常出现,您可以阅读有关使用“翻译”快速从字符串中删除杂物的信息:stackoverflow.com/questions/50444346/…
-
如何标记句子?
标签: python pandas dataframe tokenize