【发布时间】:2019-10-16 17:32:20
【问题描述】:
想从一个数据框中获取一个 cmets 列表,首先解析成一个句子列表,然后在第二次通过时,按单词解析。需要这个输入到 word2vec 模型,genism。
已经使用 nltk 中的 sent_tokenize 进行了一次标记化,但是如果我在那之后尝试 word_tokenize ,就会遇到问题,因为它不再是字符串,而是需要类似对象的字符串或字节。
import nltk
print(df)
ID Comment
0 Today is a good day.
1 Today I went by the river. The river also flow...
2 The water by the river is blue, it also feels ...
3 Today is the last day of spring; what to do to...
df['sentences']=df['Comment'].dropna().apply(nltk.sent_tokenize)
df['word']=df['sentences'].dropna().apply(nltk.word_tokenize)
在尝试将句子转换为单词之后 TypeError:预期的字符串或类似字节的对象
【问题讨论】:
-
NLTK-based text processing with pandas 上的这篇文章主要是您要查找的内容。
标签: python nlp tokenize word2vec