[英]gensim.corpora Dictionary type error interprets tokenized column as single string
这是有问题的代码:
from gensim.corpora import Dictionary
tweets_dictionary = Dictionary(df.tokenized)
Panda Dataframe df 的构建方式如下两列“created_at”和“tokenized”。 “tokenized”由一系列单词组成:
运行有问题的代码时收到以下错误消息:
TypeError: doc2bow expects an array of unicode tokens on input, not a single string
这对我来说很奇怪,因为标记化的列不是单个字符串。 我尝试将列转换为单个列表、列表列表和元组,但到目前为止没有任何效果....提前感谢您的帮助!
好的......我很愚蠢:将“df.tokenized”放入列表中有效,我只是忘记在执行之前保存代码。
所以正确的代码是:
from gensim.corpora import Dictionary
tweets_dictionary = Dictionary([df.tokenized])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.